Skip to content

Refactor journal_append_generic() - Separate concerns #107

@flyingrobots

Description

@flyingrobots

Part of SRP Refactoring (Priority 1: Core Infrastructure)

Current Problem

journal_append_generic() in src/journal/writer.c mixes buffer management, encoding, and batching logic.

Refactoring Plan

Split into focused functions:

  • prepare_journal_buffer() - Allocate and manage buffer
  • encode_edges_batch() - CBOR encoding only
  • should_commit_batch() - Batch size decision logic
  • commit_journal_batch() - Commit creation only

Acceptance Criteria

  • Original function replaced with orchestrator
  • Buffer management separated from encoding
  • Batching logic isolated and testable
  • Each function has single responsibility
  • Unit tests for each new function
  • No regression in functionality

Technical Notes

  • Consider extracting buffer management to separate module
  • Make batch size configurable
  • Ensure thread safety if needed

Related to SRP_REFACTORING_PLAN.md Priority 1.2

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