-
Notifications
You must be signed in to change notification settings - Fork 336
feat: Improve search speed by chunking long time range searches into smaller incremental search windows. #1125
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "@hyperdx/app": minor | ||
| --- | ||
|
|
||
| feat: Improve search speed by chunking long time range searches into smaller incremental search windows. |
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -33,18 +33,122 @@ function queryKeyFn( | |||||||
| return [prefix, config, queryTimeout]; | ||||||||
| } | ||||||||
|
|
||||||||
| type TPageParam = number; | ||||||||
| // Time window configuration - progressive bucketing strategy | ||||||||
| const TIME_WINDOWS_MS = [ | ||||||||
| 6 * 60 * 60 * 1000, // 6h | ||||||||
| 6 * 60 * 60 * 1000, // 6h | ||||||||
| 12 * 60 * 60 * 1000, // 12h | ||||||||
| 24 * 60 * 60 * 1000, // 24h | ||||||||
| ]; | ||||||||
|
|
||||||||
| type TimeWindow = { | ||||||||
| startTime: Date; | ||||||||
| endTime: Date; | ||||||||
| windowIndex: number; | ||||||||
| }; | ||||||||
|
|
||||||||
| type TPageParam = { | ||||||||
| windowIndex: number; | ||||||||
| offset: number; | ||||||||
| }; | ||||||||
|
|
||||||||
| type TQueryFnData = { | ||||||||
| data: Record<string, any>[]; | ||||||||
| meta: ColumnMetaType[]; | ||||||||
| chSql: ChSql; | ||||||||
| window: TimeWindow; | ||||||||
| }; | ||||||||
|
|
||||||||
| type TData = { | ||||||||
| pages: TQueryFnData[]; | ||||||||
| pageParams: TPageParam[]; | ||||||||
| }; | ||||||||
|
|
||||||||
| const queryFn: QueryFunction<TQueryFnData, TQueryKey, number> = async ({ | ||||||||
| // Generate time windows from date range using progressive bucketing | ||||||||
| function generateTimeWindows(startDate: Date, endDate: Date): TimeWindow[] { | ||||||||
| const windows: TimeWindow[] = []; | ||||||||
| let currentEnd = new Date(endDate); | ||||||||
| let windowIndex = 0; | ||||||||
|
|
||||||||
| while (currentEnd > startDate) { | ||||||||
| const windowSize = | ||||||||
| TIME_WINDOWS_MS[windowIndex] || | ||||||||
| TIME_WINDOWS_MS[TIME_WINDOWS_MS.length - 1]; // use largest window size | ||||||||
| const windowStart = new Date( | ||||||||
| Math.max(currentEnd.getTime() - windowSize, startDate.getTime()), | ||||||||
| ); | ||||||||
|
|
||||||||
| windows.push({ | ||||||||
| endTime: new Date(currentEnd), | ||||||||
| startTime: windowStart, | ||||||||
| windowIndex, | ||||||||
| }); | ||||||||
|
|
||||||||
| currentEnd = windowStart; | ||||||||
| windowIndex++; | ||||||||
| } | ||||||||
|
|
||||||||
| return windows; | ||||||||
| } | ||||||||
|
|
||||||||
| // Get time window from page param | ||||||||
| function getTimeWindowFromPageParam( | ||||||||
| config: ChartConfigWithDateRange, | ||||||||
| pageParam: TPageParam, | ||||||||
| ): TimeWindow { | ||||||||
| const [startDate, endDate] = config.dateRange; | ||||||||
| const windows = generateTimeWindows(startDate, endDate); | ||||||||
| const window = windows[pageParam.windowIndex]; | ||||||||
| if (window == null) { | ||||||||
| throw new Error('Invalid time window for page param'); | ||||||||
|
Comment on lines
+102
to
+103
|
||||||||
| if (window == null) { | |
| throw new Error('Invalid time window for page param'); | |
| throw new Error(`Invalid time window for page param with windowIndex: ${pageParam.windowIndex}`); |
Copilot
AI
Sep 3, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using the last page's window in flattenData may not represent the correct time window for the flattened data. Consider using the first page's window or creating a merged window that spans from the first to last page's time range.
Uh oh!
There was an error while loading. Please reload this page.