Repository navigation
fix(transactions): declare the tables the cached transactions list embeds - #33
Merged
Merged
Conversation
…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.
This was referenced Oct 12, 2026
Merged
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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::queryForInternaleager-loads these inside core-api's cached list query:items;journal.debitAccountandjournal.creditAccount;subject,payer,payee,initiatorandcontextmorphs.Before this PR the list's cache key only changed when
transactionsitself 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.phpnow declares$apiCacheDependencies:itemstransaction_itemsjournal,journal.debitAccount,journal.creditAccountledger_journals,ledger_accountsledger_invoicesledger_invoicessubjectandcontextcontacts,vendorscontacts,vendorspayer/payeecompaniescompaniespayer/payeemorphTo relations have no single related table, so their targets are declared as table names.
Deliberately left out:
ordersanddrivers, which ledger also writes intosubject. 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).initiatoris 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
$apiCacheDependenciessupport. With an older core-api the property is unused and this change is inert.Tests
The new test in
server/tests/Models/ModelContractsTest.phpasserts:transaction_items,ledger_journalsandledger_accounts;ledger_invoices,companies).It doesn't call core-api's new resolver, so it passes against the released core-api that CI installs.
Validation
php scripts/pest-runner.php): 302 passed, 7 failed.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…, andpurchase-rate invoices cover quote items….release/v0.0.13without this change (301 passed, 7 failed), so they're unrelated to it.php-cs-fixerdry-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
$apiCacheDependenciesonce core-api#301 lands; that's tracked there.