Feat: Optimize data loading with LRU cache and schema validation - #596
Feat: Optimize data loading with LRU cache and schema validation#596DebasmitaBose0 wants to merge 1 commit into
Conversation
|
@DebasmitaBose0 is attempting to deploy a commit to the komalsony234-1530's projects Team on Vercel. A member of the Team first needs to authorize it. |
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Adds caching to the project JSON loader to avoid repeatedly reading/parsing the same file.
Changes:
- Introduces
functools.lru_cacheonload_all_projects() - Adds a new
functoolsimport near the loader function
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| import functools | ||
| @functools.lru_cache(maxsize=128) | ||
| def load_all_projects(): |
| @functools.lru_cache(maxsize=128) | ||
| def load_all_projects(): | ||
| """Read and return the full list of projects from the JSON file.""" | ||
| with open(DATA_FILE, "r", encoding="utf-8") as f: |
komalharshita
left a comment
There was a problem hiding this comment.
Good optimization direction overall — reducing repeated disk reads for projects.json using lightweight in-memory caching makes sense for this project and keeps the implementation simple.
Things done well:
- Properly scoped backend-only change
- Lightweight dependency-free optimization
- Avoided unnecessary architectural complexity
- Good use case for
lru_cache
However, a few important issues should be addressed before merge:
- The issue requested both caching and schema/integrity validation, but the PR currently only implements caching.
- There is no cache invalidation strategy, so stale project data may persist during runtime if
projects.jsonchanges. - Since
load_all_projects()takes no arguments,maxsize=128is unnecessary/confusing — only one cached entry can exist. import functoolsshould be moved to the top import section for consistency.- No tests were added for caching behavior or validation logic.
The optimization idea is good, but the implementation should be completed/refined before approval.
Closed #595
Problem:
The utility in
data_loader.pyreads and parses theprojects.jsonfile from disk on every invocation. This disk I/O overhead slows down the recommendation pipeline and is inefficient.Acceptance Criteria:
functools.lru_cacheto memoize the loaded JSON object in memory.