Repository navigation
feat(payments): add per-plan event rate limits and retention - #922
Open
Priyanshubhartistm wants to merge 2 commits into
Open
Priyanshubhartistm wants to merge 2 commits into
Priyanshubhartistm wants to merge 2 commits into
Conversation
Signed-off-by: Priyanshubhartistm <bhartipriyanshustm@gmail.com>
🦋 Changeset detectedLatest commit: a279295 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Collaborator
Coverage Report for CI Build 39581695383Coverage increased (+0.2%) to 74.378%Details
Uncovered ChangesNo uncovered changes found. Coverage RegressionsNo coverage regressions found. Coverage Stats💛 - Coveralls |
[Medium impact] The PR appears safe to merge; no new actionable issues were found.
|
…an for 60s Signed-off-by: Priyanshubhartistm <bhartipriyanshustm@gmail.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Builds on the subscription lifecycle (#909). Nothing changes unless
payments.enabledis true and a plan setslimits.rateLimitsorlimits.retentionMaxDays(settings and validation already exist from #849).EventMessageHandler.isRateLimiteduses the limits of the sender's plan in place oflimits.event.rateLimitswhile the subscription gives access (grace included). An empty list means no limit. Everyone else, and a subscriber whose subscription ended or whose plan was removed from the settings, keeps the global limits. Counters are keyed exactly as before (<pubkey>:events:<period>), whitelists still apply.<pubkey>:subscription-plan(plan:<id>ornone) with a TTL that never outlives access, andisUserAdmittedfills it when it reads the subscription, so there is no extra database read per event. If a read fails the global limits apply and nothing is cached.deleteExpiredAndRetained) takesplanRetention. Events of subscribers on a plan withretentionMaxDaysare purged at the plan's window, everyone else at the global one, with the kind and pubkey whitelists unchanged. A subscriber counts only while their access lasts, so once it ends their events fall back to the global window at the next pass. The query is the same as before when no plan sets a retention.CONFIGURATION.mddescribes both settings.Related Issue
Closes #921
Motivation and Context
Rate limits and retention were global, so a premium subscriber got the same limits as everyone else. This is the "higher tiers get better rate limits and longer event retention" part of the tiered access.
A plan retention only applies while
limits.event.retention.maxDaysis set (the purge does not run without it). Per-plan connection and subscription-count limits are not part of this PR.How Has This Been Tested?
isRateLimited(plan vs global, empty list, kinds, expired, lapsed and grace, removed plan, whitelist, subscriptions off, cache hit/miss/error/TTL, database error), the plan cached byisUserAdmitted, the purge query with plan retention (exact SQL, whitelists, several plans, shorter windows, expired subscribers, invalid values) andMaintenanceService. Reverting the access check, the cache read, the global exclusion, the expired filter or the subscriptions-enabled check each fails a test.pnpm lint,pnpm check:deps,pnpm run build:check,pnpm run build,pnpm run verify:cli:build,pnpm run test:unit(2547 passing),pnpm run test:cli(105 passing).