Skip to content

Feat: Optimize data loading with LRU cache and schema validation - #596

Closed
DebasmitaBose0 wants to merge 1 commit into
komalharshita:mainfrom
DebasmitaBose0:enhancement/lru-caching-dataloader
Closed

Feat: Optimize data loading with LRU cache and schema validation#596
DebasmitaBose0 wants to merge 1 commit into
komalharshita:mainfrom
DebasmitaBose0:enhancement/lru-caching-dataloader

Conversation

@DebasmitaBose0

Copy link
Copy Markdown

Closed #595

Problem:
The utility in data_loader.py reads and parses the projects.json file from disk on every invocation. This disk I/O overhead slows down the recommendation pipeline and is inefficient.
Acceptance Criteria:

  • Decorate the data loading function with functools.lru_cache to memoize the loaded JSON object in memory.
  • Introduce a startup check to validate the JSON file's integrity and schema before caching.

Copilot AI review requested due to automatic review settings May 25, 2026 16:18
@vercel

vercel Bot commented May 25, 2026

Copy link
Copy Markdown

@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.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_cache on load_all_projects()
  • Adds a new functools import near the loader function

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread utils/data_loader.py
Comment on lines +11 to 13
import functools
@functools.lru_cache(maxsize=128)
def load_all_projects():
Comment thread utils/data_loader.py
Comment on lines +12 to 15
@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 komalharshita left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.json changes.
  • Since load_all_projects() takes no arguments, maxsize=128 is unnecessary/confusing — only one cached entry can exist.
  • import functools should 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

LRU Caching & Strict Schema Validation

3 participants