BOM Rows should be cached #12
Labels
No labels
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
ckreidl/katana#12
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Except for just a few products, BOM rows typically do not change. Those that do change (Tea of the Month boxes) only really chance once a month when we roll over to the next month's contents. We should extend our caching to include BOM rows to speed up MO generation as these are fetched from Katana every time we enter the MO module.
@coderabbitai plan
Coding Plan
Summary
clearByQueryType,--clearCache) without requiring new CLI optionsDesign Choices
Design Choice 1: Caching strategy for BOM data
Options Considered:
product_variant_idChosen Option: 1
Rationale: This matches the dominant "fetch all" pattern in
listBomRowsForVariants(), minimizes complexity, and aligns with the ticket's observation that BOM rows are stable data. A single cache check replaces all BOM API calls.💡 User Tips
Regenerate the plan with different choices with
@coderabbitai <feedback>.Implementation Steps
Phase 1: Extend Cache Infrastructure for Entity-Based Data
Add support for non-range-based caching to the existing cache infrastructure. The current design is optimized for time-series data with date ranges; BOM rows require simpler entity-based caching with TTL expiration.
Task 1: Add BOM Configuration to Query Config
Define BOM rows as a cacheable query type with entity-based (non-range) semantics.
packages/katana-mo-cli/src/cache/queryConfig.tsto addbomRowsquery typeisRangeBased: false)Task 2: Add Entity-Based Storage Methods to RecordStore
Extend the data access layer to support storing and retrieving entity-based cached data without range tracking.
packages/katana-mo-cli/src/cache/recordStore.tsto add methods for entity-based cachingcached_recordstable)Task 3: Add Entity Caching Methods to CacheManager
Provide high-level API for entity-based caching that mirrors the existing
getCachedOrFetchpattern but without range logic.packages/katana-mo-cli/src/cache/cacheManager.tsto add entity-based caching methodgetEntityCachedOrFetch<T>()method that checks for valid cached entity data, fetches if missing/expired, and stores resultsclearByQueryType()for invalidation🤖 Prompt for AI agents
Phase 2: Implement Cached BOM Fetching
Create cached wrapper functions for BOM fetching and integrate them into the MO generation pipeline.
Task 1: Create Cached BOM Fetch Functions
Add cached wrappers for BOM fetching that use the new entity-based caching infrastructure.
packages/katana-mo-cli/src/api/cachedKatana.tsfetchBomRowsCached()that wrapslistBomRowsForVariants()with entity cachingCacheManager.getEntityCachedOrFetch()method withbomRowsquery typeTask 2: Update Pipeline to Use Cached BOM Fetching
Integrate cached BOM fetching into both MO generation pipelines.
packages/katana-mo-cli/src/runPipeline.tsto use cached BOM functionsfetchPipelineData()(general mode) to call cached BOM function instead of directlistBomRowsForVariants()fetchSoPipelineData()(sales orders mode) to use cached BOM data with filteringcacheManagerto the cached BOM function (following existing pattern from demand fetching)cacheManageris null)Task 3: Ensure Cache Invalidation Support
Verify BOM cache integrates properly with existing invalidation mechanisms.
packages/katana-mo-cli/src/cache/cacheManager.tsinvalidation mappings if neededbomRowsto the entity type mapping ininvalidateByEntityType()--clearCacheCLI flag clears BOM cache along with other cached data🤖 Prompt for AI agents
Research
The codebase has a sophisticated file-based SQLite caching system in
packages/katana-mo-cli/src/cache/that currently supports range-based caching for time-series data (inventoryMovements). Key components include:SqliteCachefor database operationsRecordStorefor data accessCacheManagerfor orchestrationqueryConfig.tsfor defining cacheable query typesBOM rows are fetched via two patterns:
listBomRowsForVariants()which fetches all rows and filters client-sidelistBomRowsForVariantIds()which fetches per-variantBoth functions reside in
packages/katana-mo-cli/src/api/katana.tsand are called frompackages/katana-mo-cli/src/runPipeline.ts.🚀 Next Steps
🤖 All AI agent prompts combined
💡 Iterate on the plan with:
@coderabbitai <feedback>💬 Have feedback or questions? Drop into our discord!
@coderabbitai while we will be caching each individual record, our call to Katana's API in
listBomRowsForVariantssimply requests all BOM Rows by not specifying any parameters. are we just going to pretend new records within Katana don't exist if there's cached records within the TTL?🧩 Analysis chain
🏁 Script executed:
Length of output: 410
@chris-kreidlYes, that's exactly the trade-off with TTL-based caching. During the 24-hour TTL window, any new BOM rows created in Katana won't be visible until either:--clearCacheBased on issue
#12, this seems like an acceptable trade-off for your use case since:Mitigation strategies we could consider:
Manual invalidation (already in plan): When you know recipes changed (e.g., updating Tea of the Month), run with
--clearCacheto force a refreshShorter TTL: We could reduce from 24 hours to something like 4-6 hours if you want fresher data while still getting cache benefits
Force-refresh flag: Add a specific
--refreshBomflag to invalidate just BOM cache without clearing everythingHybrid approach: Cache per-variant with cross-population (Design Choice 1, Option 3), which could allow partial cache invalidation - but adds complexity
My recommendation: Stick with the current plan (24-hour TTL, manual
--clearCache) since your BOM changes are infrequent and predictable. If you find the staleness problematic in practice, we can always add more granular controls later.Does this trade-off work for your workflow, or would you prefer a different approach?