Skip to content

fix: TTL bump on markets storage reads#1017

Open
ogaziedaniel80-droid wants to merge 1 commit into
Predictify-org:masterfrom
ogaziedaniel80-droid:task/markets-ttl
Open

fix: TTL bump on markets storage reads#1017
ogaziedaniel80-droid wants to merge 1 commit into
Predictify-org:masterfrom
ogaziedaniel80-droid:task/markets-ttl

Conversation

@ogaziedaniel80-droid

Copy link
Copy Markdown

Summary

Bump persistent storage TTL on hot read paths in markets to prevent frequently-accessed markets from expiring.

Changes

  • markets.rs: MarketStateManager::get_market() extends persistent TTL on cache miss
  • queries.rs: QueryManager::get_market_from_storage() extends persistent TTL on query reads
  • 4 focused tests added
  • Changed get_market_from_storage visibility to pub(crate) for testability

Acceptance Criteria

  • Implementation matches description
  • Tests added (4 tests: cache miss bump, cache hit non-bump, max_ttl clamp, query path bump)
  • Tests passing (run cargo test --package predictify-hybrid)
  • Lint passing (run cargo clippy)
  • Docs updated (inline doc comments)

Implementation Details

Problem

Market storage reads on hot paths did not bump persistent TTL, meaning frequently-queried markets could expire even while actively used.

Solution

Added TTL extension calls using MARKET_TTL_LEDGERS.min(env.storage().max_ttl()) on two hot read paths:

  1. Cache miss in get_market() (markets.rs): When a market is fetched from persistent storage and not in the instance cache, the persistent TTL is extended to the full market tier.

  2. Direct reads in get_market_from_storage() (queries.rs): All query functions that bypass the instance cache now extend persistent TTL on read.

Tests

  • test_get_market_bumps_persistent_ttl_on_cache_miss — verifies TTL refresh on cache miss
  • test_get_market_cache_hit_does_not_bump_persistent_ttl — verifies cache hits only bump instance TTL
  • test_get_market_ttl_bump_respects_max_ttl — verifies TTL never exceeds max_ttl()
  • test_get_market_from_storage_bumps_persistent_ttl — verifies query path TTL refresh

Closes #861

Bump persistent storage TTL on hot read paths in markets to prevent
frequently-accessed markets from expiring.

- MarketStateManager::get_market(): extend TTL on cache miss (persistent read)
- QueryManager::get_market_from_storage(): extend TTL on query reads
- Added 4 focused tests covering cache miss bump, cache hit non-bump, max_ttl clamp
- Changed get_market_from_storage visibility to pub(crate) for testability

Closes Predictify-org#861
@drips-wave

drips-wave Bot commented Jul 26, 2026

Copy link
Copy Markdown

@ogaziedaniel80-droid Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add TTL bump on markets storage reads (buffer #5)

1 participant