Repository navigation
Read Cursor's usage in pages of 1000, in parallel, and only since the cache - #24
Merged
Merged
Conversation
…ce the cache Reading Cursor's usage list asked for a year of events in pages of 100, one after another, then for the billing cycle, all under a 45 s limit. Each request takes seconds, so on this account (about 2,000 events) a cold read ran into the limit at 900 events, saved a partial list, and was not retried for five minutes. The figures came from the notes in B3010_cursor-agent and the same approach in cursor2api. - Pages hold 1000 events, the most the service accepts, and the pages after the first are fetched four at a time. - The billing cycle and the plan name are asked for at the same time as the events, and as each other, which also makes quota's check faster. - A full read of the year runs once a week. In between, a read asks only from 48 hours before the newest cached event and replaces the cached events from there on, which also picks up late changes to recent ones. - The trace callbacks are serialized, since requests now run at once. Measured against the live account with the same index: a cold read takes 10.2 s and gets all 1,982 events (it took 46.9 s and stopped at 900); a read after the cache goes stale takes 3.2 s and ends with the same 1,982 events and 413 conversations.
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.
Summary
Reading Cursor's usage list asked for a year of events in pages of 100, one after another, then for the billing cycle, all under a 45 s limit. Each request takes seconds, so on a ~2,000-event account a cold read hit the limit at 900 events, saved a partial list and waited five minutes before trying again.
quota).Test plan
go vet ./...,gofmt -l .,go test ./...,go test -race ./internal/cursorusage