Usage estimator performance#8198
Conversation
There was a problem hiding this comment.
Code Review
This change introduces conditional querying of the optimized operations_by_target_hourly table based on a configured creation date. To ensure correctness, the Zod schema default for OPERATIONS_BY_TARGET_TABLE_CREATED_AT should be changed from new Date() to a deterministic fixed date like new Date(0). Additionally, the year in the configured date 2027-06-11T00:00:00Z should be corrected to prevent queries from falling back to the unoptimized table.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
|
🐋 This PR was built and pushed to the following Docker images: Targets: Platforms: Image Tags: |
|
I think we could use The query you're optimizing is from The time window there looks like this: console/packages/services/commerce/src/rate-limit/limiter.ts Lines 70 to 73 in 27a58e5 And we sum the targets by organization: so yeah, we could do: SELECT
sum(total) as total,
organization
FROM
monthly_overview PREWHERE date = '2026-07-01'
GROUP BY
organization
# Elapsed: 0.053s Read: 2,650 rows (38.85 KB) |
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
abc8319 to
38129cf
Compare
| .number() | ||
| .min(now.getFullYear() - 1) | ||
| .max(new Date(now.setMonth(now.getMonth() + 1)).getFullYear()); | ||
| .min(now.getUTCFullYear() - 1) |
There was a problem hiding this comment.
We should always use UTC to avoid timezone issues.

Background
I've noticed several spikes in IOWait duration in Clickhouse. This could be caused by a number of things, but one of them is if the read amount is excessive.
Usage estimator polls for usage data using our
operations_hourlytable. This table has an unoptimized order for querying a target's operation count without any filters.Description
This adjusts the operation to use the new table that is ideal for this query.
This results in significantly fewer rows being read and a much faster response.
Before:

After:
