Add date-ranged usage query method - #126
Merged
Merged
Conversation
nsheff
force-pushed
the
feat/usage-endpoint
branch
from
August 22, 2026 20:19
1e59569 to
a10f0bb
Compare
Contributor
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
Suppressed comments (2)
bbconf/bbagent.py:494
UsageResponse.countis currently set tolen(results), which becomes the page size after limit/offset rather than the total number of matching keys. Also, NULL/empty keys are filtered out in Python (if f[0]), which means pagination can be inconsistent (limit/offset are applied before filtering) and clients may receive fewer thanlimititems unexpectedly.
count=len(results),
bbconf/bbagent.py:450
- The docstring states
date_from <= date_to, andlimit/offsetare used for pagination, but there is no input validation. Passingdate_from > date_toor negativelimit/offsetwill currently produce confusing results (empty pages or DB-dependent behavior) rather than a clear error.
if event_type not in usage_map:
raise ValueError(
f"Invalid event_type '{event_type}'. Must be one of: "
f"{', '.join(usage_map)}."
)
Moves the empty-key filter into the WHERE clause so it runs before LIMIT/OFFSET, fixing inconsistent page sizes.
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.
What this does
Adds a new way to read BEDbase usage counts (BED/BEDset views, searches, file downloads) for a chosen date range, without the existing 20-item cap.
Today the only usage readout (
get_detailed_usage) returns just the top 20 items summed over all time. The stored data is actually per-item and time-stamped, but there was no way to query it by date or to get more than 20 rows.Changes
BedBaseAgent.get_usage(event_type, date_from, date_to, limit, offset)that groups usage by item, sums the counts, optionally filters to a date window, and pages results. Read-only.UsageItem,UsageResponse).The existing
get_detailed_usageis left unchanged.Why
Enables accurate per-month usage reporting (used by the
bedhost/v1/usageendpoint in a companion PR) instead of a top-20 all-time snapshot.