Skip to content

[Bug]: In-memory cache in data_loader.py is declared but never used — every request re-reads projects.json from disk #483

@Daksh7785

Description

@Daksh7785

Describe the bug

utils/data_loader.py declares a module-level cache variable and a clear_cache() function, but load_all_projects() never reads from or writes to the cache:

_projects_cache = None  # declared but never read

def load_all_projects():
    with open(DATA_FILE, "r", encoding="utf-8") as f:
        return json.load(f)  # ← no cache check, file read every call

This means every call to /api/recommend, every project detail page load (find_project_by_id), and every homepage render (get_project_stats) triggers a full disk read and JSON parse. clear_cache() resets a variable that is never read — it is a dead function.

Expected behavior

load_all_projects() should check the cache first and only read the file on a miss.

Suggested fix

def load_all_projects():
    global _projects_cache
    if _projects_cache is None:
        with open(DATA_FILE, "r", encoding="utf-8") as f:
            _projects_cache = json.load(f)
    return _projects_cache

Files affected

  • utils/data_loader.py

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions