Skip to content

Add date-ranged usage query method - #126

Merged
khoroshevskyi merged 2 commits into
devfrom
feat/usage-endpoint
Aug 24, 2026
Merged

Add date-ranged usage query method#126
khoroshevskyi merged 2 commits into
devfrom
feat/usage-endpoint

Conversation

@nsheff

@nsheff nsheff commented Aug 22, 2026

Copy link
Copy Markdown
Member

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

  • New 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.
  • Two small response models (UsageItem, UsageResponse).

The existing get_detailed_usage is left unchanged.

Why

Enables accurate per-month usage reporting (used by the bedhost /v1/usage endpoint in a companion PR) instead of a top-20 all-time snapshot.

@nsheff
nsheff force-pushed the feat/usage-endpoint branch from 1e59569 to a10f0bb Compare August 22, 2026 20:19
@nsheff
nsheff requested a balanced review from Copilot August 22, 2026 20:32

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.count is currently set to len(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 than limit items unexpectedly.
            count=len(results),

bbconf/bbagent.py:450

  • The docstring states date_from <= date_to, and limit/offset are used for pagination, but there is no input validation. Passing date_from > date_to or negative limit/offset will 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)}."
            )

Comment thread bbconf/bbagent.py
Moves the empty-key filter into the WHERE clause so it runs
before LIMIT/OFFSET, fixing inconsistent page sizes.
@khoroshevskyi
khoroshevskyi merged commit 6077bc2 into dev Aug 24, 2026
4 checks passed
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.

3 participants