Skip to content

Cache expiration_time in SubscriptionLedger to eliminate redundant arithmetic on every call#401

Merged
akru merged 4 commits intofeat/rws2_0from
copilot/sub-pr-381-another-one
Nov 28, 2025
Merged

Cache expiration_time in SubscriptionLedger to eliminate redundant arithmetic on every call#401
akru merged 4 commits intofeat/rws2_0from
copilot/sub-pr-381-another-one

Conversation

Copy link
Contributor

Copilot AI commented Nov 28, 2025

Addresses performance feedback from #381 (#381 (comment)). For Daily subscriptions, subscription.issue_time + duration_ms was computed on every call() invocation.

Changes

  • Added expiration_time: Option<Moment> field to SubscriptionLedger

    • Some(issue_time + days * DAYS_TO_MS) for Daily subscriptions
    • None for Lifetime subscriptions
  • Updated call() to use cached value instead of recalculating expiration on each invocation

  • Extended v1→v2 migration to compute and populate expiration_time for existing Daily subscriptions

// Before: computed on every call
SubscriptionMode::Daily { days } => {
    let duration_ms = Moment::from(days * DAYS_TO_MS);
    if now < subscription.issue_time + duration_ms { ... }
}

// After: cached at subscription creation
SubscriptionMode::Daily { .. } => {
    if let Some(ref expiration_time) = subscription.expiration_time {
        if now < *expiration_time { ... }
    }
}

All 27 tests pass.


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 3 commits November 28, 2025 15:13
…ization

Co-authored-by: akru <786394+akru@users.noreply.github.com>
…lity

Co-authored-by: akru <786394+akru@users.noreply.github.com>
Co-authored-by: akru <786394+akru@users.noreply.github.com>
@akru akru marked this pull request as ready for review November 28, 2025 15:21
@akru akru merged commit db2dc09 into feat/rws2_0 Nov 28, 2025
@akru akru deleted the copilot/sub-pr-381-another-one branch November 28, 2025 15:22
Copilot AI changed the title [WIP] Add expiration_time field to RWS pallet refactor Cache expiration_time in SubscriptionLedger to eliminate redundant arithmetic on every call Nov 28, 2025
Copilot AI requested a review from akru November 28, 2025 15:22
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.

2 participants