Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

misc(usage): Scope usage caching to the charge filter level #2678

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

vincent-pochet
Copy link
Collaborator

Context

Today caching for usage data is scope to the charge.
When an event is received for a specific billable metric code will invalidate the cache for all charges attached to it for the customer's plan. The cache will leave until the end of the billing period or until a new event is received for the same billable metric code and subscription.
This logic avoid recomputing the complete charge aggregation every time the customer usage is requested.

This logic was fine until the introduction of charge filters.
Aggregation for filters are done one by one for every filter, and stored in cache using the same charge cache key (ie: all filtered aggregations are grouped inside the same charge cached bucket). When an event matching a filter is received it invalidate the cache for all filters, meaning that when fetching the usage we have to resegregate it for every single filter even if nothing new was received for the majority of them.

Description

This PR refactors some parts of the usage computation and adds a new caching logic to scope the caching up to the charge filter when applicable and keeping the actual caching when no filters are attached to the charge.

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.

1 participant