-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor: added field for supply-change endpoint #41
Conversation
WalkthroughThis update introduces a new caching system for supply change data using Redis. A new environment variable, Changes
Sequence Diagram(s)sequenceDiagram
actor User
participant SupplyService
participant SupplyCache
participant Redis
User ->> SupplyService: getSupplyChange(range)
SupplyService ->> SupplyCache: getSupplyChange(range)
SupplyCache ->> Redis: Fetch supply change data
Redis -->> SupplyCache: Return cached data (if exists)
SupplyCache -->> SupplyService: Supply change data or null
alt Cache Hit
SupplyService -->> User: Return cached supply change
else Cache Miss
SupplyService ->> SupplyService: Calculate supply change
SupplyService ->> SupplyCache: setSupplyChange(range, data)
SupplyCache ->> Redis: Store supply change data
SupplyService -->> User: Return calculated supply change
end
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (6)
- .env.example (1 hunks)
- src/core/config/config.dto.ts (1 hunks)
- src/core/config/config.schema.ts (2 hunks)
- src/core/config/config.ts (3 hunks)
- src/modules/supply/services/supply.cache.ts (2 hunks)
- src/modules/supply/services/supply.service.ts (1 hunks)
Files skipped from review due to trivial changes (4)
- .env.example
- src/core/config/config.dto.ts
- src/core/config/config.schema.ts
- src/core/config/config.ts
Additional comments not posted (7)
src/modules/supply/services/supply.cache.ts (4)
11-11
: Initialization ofchangePrefix
property.The addition of the
changePrefix
property to manage keys specifically for supply changes is a good practice as it helps in distinguishing different types of cached data.
26-28
: Ensure proper use of TTL insetSupplyChange
method.The method correctly sets the TTL for caching supply change data, which aligns with the new configuration parameter
SUPPLY_CHANGE_CACHE_TTL
. This should help in managing cache expiration effectively.
30-38
: Review ofgetSupplyChange
method for handling cache retrieval.This method properly checks for the existence of serialized data and returns
null
if not found, which is a good practice for cache handling. The JSON parsing is done safely with a type assertion, which is also commendable.
40-41
: Review ofcreateRedisKey
method.The method uses a functional approach to concatenate IDs with a prefix, which is a clean and efficient way to generate keys for Redis operations.
src/modules/supply/services/supply.service.ts (3)
130-137
: Review of caching logic ingetSupplyChange
.The method effectively checks the cache before computing the supply change, which is a good performance optimization. The use of
null
to indicate the absence of cache data is clear and follows common practices.
139-157
: Review ofcacheSupplyChange
method.This method is well-implemented with clear logic for computing supply changes. It handles both the scenario where previous supply data exists and when it does not, ensuring robustness. The use of
Big
for arithmetic operations is appropriate to avoid precision errors with floating-point calculations.
Line range hint
204-228
: Review ofcalculatePastDateByRange
and its usage.This method provides a flexible way to compute past dates based on different ranges, which is crucial for the functionality of this service. The implementation is straightforward and uses standard date manipulation techniques.
No description provided.