Skip to content

fix(transactions): declare the tables the cached transactions list embeds - #33

Merged
roncodes merged 1 commit into
release/v0.0.13from
fix/api-cache-dependencies
Oct 13, 2026
Merged

roncodes merged 1 commit into
release/v0.0.13from
fix/api-cache-dependencies

Conversation

@roncodes

@roncodes roncodes commented Oct 12, 2026 •

Copy link
Copy Markdown
Member

What

The cached transactions list could show stale line items, journals, accounts, invoices and parties after they were edited. This PR declares the tables that list embeds, so writes to them invalidate it.

TransactionFilter::queryForInternal eager-loads these inside core-api's cached list query:

  • items;
  • journal.debitAccount and journal.creditAccount;
  • the subject, payer, payee, initiator and context morphs.

Before this PR the list's cache key only changed when transactions itself was written, so edits to any of those were served stale until the cache expired. The resource renders the morph targets in full, e.g. an invoice's status.

Change

server/src/Models/Transaction.php now declares $apiCacheDependencies:

Entry Tables Why
items transaction_items eager-loaded line items
journal, journal.debitAccount, journal.creditAccount ledger_journals, ledger_accounts eager-loaded journal entry
ledger_invoices ledger_invoices morph target: invoice payments and refunds use it as subject and context
contacts, vendors contacts, vendors morph targets: invoice customer types used as payer / payee
companies companies morph target: the company is payer / payee

morphTo relations have no single related table, so their targets are declared as table names.

Deliberately left out: orders and drivers, which ledger also writes into subject. Both tables are written constantly (order activity, driver locations). Declaring them would invalidate the transactions list on almost every request, so a transaction's order or driver snapshot in the list may lag by up to the list cache TTL (5 min). initiator is never set by ledger code.

Every model writing those tables uses HasApiModelBehavior, so evented writes bump their versions.

Depends on

fleetbase/core-api#301, which adds $apiCacheDependencies support. With an older core-api the property is unused and this change is inert.

Tests

The new test in server/tests/Models/ModelContractsTest.php asserts:

  • the declaration;
  • that every relation path resolves to a non-morph relation, giving transaction_items, ledger_journals and ledger_accounts;
  • that the raw entries match their models' tables (ledger_invoices, companies).

It doesn't call core-api's new resolver, so it passes against the released core-api that CI installs.

Validation

  • Full ledger server suite (php scripts/pest-runner.php): 302 passed, 7 failed.
    • The 7 failures are pre-existing invoice-service tests: invoice creation normalizes malformed settings…, …applies the invoice company settings without a company session, invoice settings use the invoice company…, invoice creation without any company context…, order invoices use structured meta items…, order invoice item resolution…, and purchase-rate invoices cover quote items….
    • The same 7 fail on release/v0.0.13 without this change (301 passed, 7 failed), so they're unrelated to it.
  • php-cs-fixer dry-run on the changed files: no changes.

Docs / API impact

None for the API or postman. The extension caching docs in fleetbase.io should cover $apiCacheDependencies once core-api#301 lands; that's tracked there.

…beds

TransactionFilter::queryForInternal eager loads line items, the journal
with its debit and credit accounts, and the subject/payer/payee/
initiator/context morphs inside the cached list query, so edits to any
of them were served stale until the cache expired. Declare them as
$apiCacheDependencies so core-api's list cache key carries their
versions: the relation paths, plus the morph target tables ledger
writes (ledger_invoices, contacts, vendors, companies). Orders and
drivers are left out because they are written constantly.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant