Skip to content

Refactor cache_rebuild_internal() - Split 67-line monster #106

@flyingrobots

Description

@flyingrobots

Part of SRP Refactoring (Priority 1: Core Infrastructure)

Current Problem

cache_rebuild_internal() in src/cache/builder.c is a 67-line function doing everything - violates SRP.

Refactoring Plan

Split into focused functions:

  • prepare_cache_rebuild() - Setup temp directory and context
  • collect_all_edges() - Gather edges from journal
  • build_edge_maps() - Create forward/reverse mappings
  • persist_cache_data() - Write bitmaps and trees
  • finalize_cache_commit() - Create commit and update refs

Acceptance Criteria

  • Original function replaced with orchestrator calling new functions
  • Each new function has single responsibility
  • Each function ≤ 20 lines
  • Unit tests for each new function
  • Integration tests still pass
  • Performance not degraded

Technical Notes

  • Use dependency injection for testability
  • Extract pure functions where possible
  • Document each function's responsibility

Related to SRP_REFACTORING_PLAN.md Priority 1.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    refactoringCode refactoring without changing functionalitytech-debtTechnical debt that needs addressing

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions