mirror of
https://github.com/hyperdxio/hyperdx
synced 2026-04-21 13:37:15 +00:00
fix: Prevent non-windowed searches from querying infinitely (#1235)
Fixes HDX-2548 This PR fixes an issue causing non-windowed searches to query the entire date range infinitely. ## Before https://github.com/user-attachments/assets/13daed15-b862-4b12-95d4-43a88ecabade ## After https://github.com/user-attachments/assets/058e6da8-1b2a-47e4-80ac-70ce76615a2f
This commit is contained in:
parent
5210bb86a4
commit
62eddcf20a
3 changed files with 47 additions and 2 deletions
5
.changeset/short-turtles-change.md
Normal file
5
.changeset/short-turtles-change.md
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
"@hyperdx/app": patch
|
||||
---
|
||||
|
||||
fix: Fix infinite querying on non-windowed searches
|
||||
|
|
@ -237,6 +237,45 @@ describe('useOffsetPaginatedQuery', () => {
|
|||
expect(result.current.data?.window.direction).toEqual('DESC');
|
||||
});
|
||||
|
||||
it('should finish pagination when windowing is not being used', async () => {
|
||||
const config = createMockChartConfig({
|
||||
dateRange: [
|
||||
new Date('2024-01-01T00:00:00Z'),
|
||||
new Date('2024-01-02T00:00:00Z'),
|
||||
] as [Date, Date],
|
||||
orderBy: 'ServiceName', // Not using windowing
|
||||
});
|
||||
|
||||
// Mock the reader to return empty data for the first page
|
||||
mockReader.read
|
||||
.mockResolvedValueOnce({
|
||||
done: false,
|
||||
value: [
|
||||
{ json: () => ['timestamp', 'message'] },
|
||||
{ json: () => ['DateTime', 'String'] },
|
||||
],
|
||||
})
|
||||
.mockResolvedValueOnce({ done: true });
|
||||
|
||||
const { result } = renderHook(() => useOffsetPaginatedQuery(config), {
|
||||
wrapper,
|
||||
});
|
||||
|
||||
await waitFor(() => expect(result.current.isLoading).toBe(false));
|
||||
|
||||
// Should have data from the entire range, without windowing
|
||||
expect(result.current.data).toBeDefined();
|
||||
expect(result.current.data?.window.windowIndex).toBe(0);
|
||||
expect(result.current.data?.window.startTime).toEqual(
|
||||
new Date('2024-01-01T00:00:00Z'), // startDate
|
||||
);
|
||||
expect(result.current.data?.window.endTime).toEqual(
|
||||
new Date('2024-01-02T00:00:00Z'), // endDate
|
||||
);
|
||||
expect(result.current.data?.window.direction).toEqual('DESC');
|
||||
expect(result.current.hasNextPage).toEqual(false); // There should be no more pages, since no results were found
|
||||
});
|
||||
|
||||
it('should handle very large time ranges with progressive bucketing', async () => {
|
||||
const config = createMockChartConfig({
|
||||
dateRange: [
|
||||
|
|
|
|||
|
|
@ -177,9 +177,10 @@ function getNextPageParam(
|
|||
};
|
||||
}
|
||||
|
||||
// If no more results in current window, move to next window
|
||||
// If no more results in current window, move to next window (if windowing is being used)
|
||||
const shouldUseWindowing = isTimestampExpressionInFirstOrderBy(config);
|
||||
const nextWindowIndex = currentWindow.windowIndex + 1;
|
||||
if (nextWindowIndex < windows.length) {
|
||||
if (shouldUseWindowing && nextWindowIndex < windows.length) {
|
||||
return {
|
||||
windowIndex: nextWindowIndex,
|
||||
offset: 0,
|
||||
|
|
|
|||
Loading…
Reference in a new issue