Add MAX_PAGING_RESULTS on hooks for performance improvements.
This commit is contained in:
1 parent
a8c1f26775
commit
fbac7518fc
17 files changed
+74
-215
No files matched your search
@@ -380,13 +380,15 @@ async function pagedRawQuery(
|
||||
.filter(n => n)
|
||||
.join('\n');
|
||||
|
||||
const count = await rawQuery(`select count(*) as num from (${query}) t`, queryParams).then(
|
||||
res => res[0].num,
|
||||
);
|
||||
const { maxResults } = filters;
|
||||
const countQuery = maxResults
|
||||
? `select count(*) as num from (select 1 from (${query}) t limit ${+maxResults}) t2`
|
||||
: `select count(*) as num from (${query}) t`;
|
||||
|
||||
const count = await rawQuery(countQuery, queryParams).then(res => res[0].num);
|
||||
const data = await rawQuery(`${query}${statements}`, queryParams, name);
|
||||
|
||||
return { data, count, page: +page, pageSize: size, orderBy, search };
|
||||
return { data, count, page: +page, pageSize: size, orderBy, search, isCapped: !!maxResults && +count >= +maxResults };
|
||||
}
|
||||
|
||||
async function rawQuery<T = unknown>(
|
||||
|
||||
@@ -26,6 +26,7 @@ export const DEFAULT_DATE_RANGE_VALUE = '24hour';
|
||||
export const DEFAULT_WEBSITE_LIMIT = 10;
|
||||
export const DEFAULT_RESET_DATE = '2000-01-01';
|
||||
export const DEFAULT_PAGE_SIZE = 20;
|
||||
export const MAX_PAGING_RESULTS = 10000;
|
||||
export const DEFAULT_DATE_COMPARE = 'prev';
|
||||
export const DEFAULT_CURRENCY = 'USD';
|
||||
|
||||
|
||||
+6
-4
@@ -470,13 +470,15 @@ async function pagedRawQuery(
|
||||
.filter(n => n)
|
||||
.join('\n');
|
||||
|
||||
const count = await rawQuery(`select count(*) as num from (${query}) t`, queryParams).then(
|
||||
res => res[0].num,
|
||||
);
|
||||
const { maxResults } = filters;
|
||||
const countQuery = maxResults
|
||||
? `select count(*) as num from (select 1 from (${query}) t limit ${+maxResults}) t2`
|
||||
: `select count(*) as num from (${query}) t`;
|
||||
|
||||
const count = await rawQuery(countQuery, queryParams).then(res => Number(res[0].num));
|
||||
const data = await rawQuery(`${query}${statements}`, queryParams, name);
|
||||
|
||||
return { data, count, page: +page, pageSize: size, orderBy };
|
||||
return { data, count, page: +page, pageSize: size, orderBy, isCapped: !!maxResults && +count >= +maxResults };
|
||||
}
|
||||
|
||||
function getSearchParameters(query: string, filters: Record<string, any>[]) {
|
||||
|
||||
@@ -174,5 +174,6 @@ export async function getQueryFilters(
|
||||
sortDescending: params?.sortDescending,
|
||||
search: params?.search,
|
||||
compare: params?.compare,
|
||||
maxResults: params?.maxResults,
|
||||
};
|
||||
}
|
||||
@@ -77,6 +77,7 @@ export const searchParams = {
|
||||
export const pagingParams = {
|
||||
page: z.coerce.number().int().positive().optional(),
|
||||
pageSize: z.coerce.number().int().positive().optional(),
|
||||
maxResults: z.coerce.number().int().positive().optional(),
|
||||
};
|
||||
|
||||
export const sortingParams = {
|
||||
|
||||
@@ -157,6 +157,7 @@ export interface SortParams {
|
||||
export interface PageParams {
|
||||
page?: number;
|
||||
pageSize?: number;
|
||||
maxResults?: number;
|
||||
}
|
||||
|
||||
export interface SegmentParams {
|
||||
@@ -172,6 +173,7 @@ export interface PageResult<T> {
|
||||
orderBy?: string;
|
||||
sortDescending?: boolean;
|
||||
search?: string;
|
||||
isCapped?: boolean;
|
||||
}
|
||||
|
||||
export interface RealtimeData {
|
||||
|
||||
Reference in new issue
Block a user