Skip to content

Extract compaction logic to Compactor class (SOLID)#2

Merged
abdellatifLabr merged 2 commits into
mainfrom
solid-compactor
Feb 26, 2026
Merged

Extract compaction logic to Compactor class (SOLID)#2
abdellatifLabr merged 2 commits into
mainfrom
solid-compactor

Conversation

@abdellatifLabr
Copy link
Copy Markdown
Owner

Summary

  • Extract compaction logic from Database class to a new Compactor class following Single Responsibility Principle
  • Created src/jsonldb/compactor.py with Compactor class
  • Database.compact() now delegates to Compactor.compact()

Changes

  • New file: src/jsonldb/compactor.py with Compactor class containing:
    • _merge_records() - merges data file records with WAL entries
    • _write_compacted_records() - writes compacted records to temp file
    • _rebuild_indexes() - rebuilds main and field indexes
  • Modified: database.py - imports Compactor, delegates compact() call
  • Not exported: Compactor is internal-only (not in public API)

Benefits

  • Database class has one reason to change (database operations)
  • Compactor class has one reason to change (compaction logic)
  • Easier to test and maintain

@abdellatifLabr abdellatifLabr merged commit 0ed1b23 into main Feb 26, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant