Skip to content

[Performance] get_reason_code_analytics re-sorts full refund history on every call — result should be cached per window #382

Description

@fati-Onchain

Contract: contracts/refund/src/lib.rs

Description

Analytics are recomputed from the full refund dataset on every call. In a live system with thousands of refunds, this is a several-hundred-millisecond operation that fails at scale. The result is deterministic for a given ledger range and can be cached.

Fix

Cache the analytics result under DataKey::AnalyticsCache(window_start, window_end) → Vec<(reason_code, count)>. Invalidate the cache only when a new refund is processed within that window.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions