Skip to content

[ADVANCED] Dead code: Unused cache implementation in data_loader.py #381

@atul-upadhyay-7

Description

@atul-upadhyay-7

Description

The utils/data_loader.py contains dead code - an unused cache mechanism that is defined but never actually implemented or used anywhere in the codebase. This adds confusion and increases maintenance overhead.

Affected File

utils/data_loader.py (lines 51-57)

Problem

The module defines a cache variable and a function to clear it:

# Cache for loaded projects
_projects_cache = None


def clear_cache():
    """Reset the in-memory project cache."""
    global _projects_cache
    _projects_cache = None

However:

  1. _projects_cache is never used in any function - load_all_projects() and find_project_by_id() always read directly from the JSON file
  2. clear_cache() is never called anywhere in the codebase
  3. There's no cache implementation - the variable is defined but no logic populates or uses it

Evidence

Search the codebase for usage:

  • load_all_projects() (lines 11-14): Opens and reads file every time
  • find_project_by_id() (lines 17-25): Calls load_all_projects() directly each time
  • No calls to clear_cache() exist anywhere

Impact

  1. Confusion: Developers might think caching is implemented and try to use it
  2. Maintenance: Dead code must be maintained, tested, and documented unnecessarily
  3. Code bloat: Adds 7 unnecessary lines to the codebase
  4. False promises: The comment "Cache for loaded projects" suggests functionality that doesn't exist

Expected Behavior

Either:

  1. Option A: Remove the dead code entirely if caching isn't needed
  2. Option B: Implement actual caching if performance optimization is the goal

Given that the project works fine without caching (10 projects in JSON), Option A is recommended.

Suggested Fix

Remove lines 51-57 from utils/data_loader.py:

# REMOVE THIS DEAD CODE:
# Cache for loaded projects
_projects_cache = None


def clear_cache():
    """Reset the in-memory project cache."""
    global _projects_cache
    _projects_cache = None

Alternatively, if caching is desired for future performance improvement, implement it properly:

_projects_cache = None


def load_all_projects():
    """Read and return the full list of projects from the JSON file."""
    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


def clear_cache():
    """Reset the in-memory project cache."""
    global _projects_cache
    _projects_cache = None

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions