cadrumo.application.modelo.participation_index_rebuild module

Rebuild the transaction participation index from the revision catalogue.

The participation index is a derived, read-side cache co-written atomically with revision persistence; the calculation-revision catalogue is the authoritative source of truth. This module regenerates the index from scratch by iterating the full finalized-revision catalogue, so a stale or corrupt index can be replaced without data loss, in line with the aeat-ledger-contract project rule.

The rebuild reads the CalculationRevisionCatalogue (the finalized revisions and their source_transaction_ids), the work-unit catalogue (for the modelo / filing_year / period axis per revision), and the ModeloRecordCatalogue / ModeloRecord rows (to attach the filing_record_id and any justificante reference to filed participations). Borrador and discarded revisions are excluded — the index records only the finalized audit surface.

See also

TransactionRevisionParticipationIndex:

Per-transaction secure object rebuilt by this module.

cadrumo.application.modelo.verification_actions._build_participation_writes():

Write-time co-emission path that keeps the index current during verification persistence.

class ParticipationRebuildStats(**data)[source]

Bases: BaseModel

Outcome of one participation-index rebuild pass.

Variables:
  • transaction_count – Number of distinct ledger transactions that gained at least one participation entry.

  • participation_count – Total number of (transaction, finalized-revision) participation entries written across all transactions.

  • revision_count – Number of finalized revisions folded into the index.

  • stale_removed_count – Number of previously persisted participation objects removed because the regenerated catalogue no longer records them — the transactions whose finalized revisions were discarded, removed, or reverted to borrador since the last rebuild.

Parameters:

data (Any)

transaction_count: NonNegativeInt
participation_count: NonNegativeInt
revision_count: NonNegativeInt
stale_removed_count: NonNegativeInt
rebuild_participation_index(*, ports)[source]

Regenerate the participation index from the finalized-revision catalogue.

Iterates every finalized CalculationRevision, resolves its modelo / filing_year / period from the work-unit catalogue and its filing_record_id from the filing-record catalogue, and writes one TransactionRevisionParticipationIndex per contributing transaction. Borrador and discarded revisions are excluded.

The regenerated set REPLACES the persisted index rather than being upserted over it: a transaction whose finalized revisions have since been discarded or removed contributes no entry here, and its stale secure object is pruned in the same atomic batch. Without that prune a removed revision would stay visible through the derived cache while the authoritative catalogue no longer records it. Returns a ParticipationRebuildStats summary.

Return type:

ParticipationRebuildStats

Parameters:

ports (ParticipationIndexRebuildPorts)