fix: paginate import history and report
This commit is contained in:
22
shared/importLogPagination.ts
Normal file
22
shared/importLogPagination.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
export const DEFAULT_IMPORT_LOG_PAGE_SIZE = 200;
|
||||
export const MAX_IMPORT_LOG_PAGE_SIZE = 500;
|
||||
|
||||
export type ImportLogPaginationInput = {
|
||||
limit?: number;
|
||||
offset?: number;
|
||||
};
|
||||
|
||||
/**
|
||||
* Normalise les limites avant toute lecture de journal. Les imports historiques
|
||||
* peuvent contenir plusieurs dizaines de milliers de lignes : l'interface ne
|
||||
* doit jamais tenter de les transférer en une seule requête.
|
||||
*/
|
||||
export function normalizeImportLogPagination(input?: ImportLogPaginationInput) {
|
||||
const requestedLimit = input?.limit ?? DEFAULT_IMPORT_LOG_PAGE_SIZE;
|
||||
const requestedOffset = input?.offset ?? 0;
|
||||
|
||||
return {
|
||||
limit: Math.min(Math.max(Math.trunc(requestedLimit), 1), MAX_IMPORT_LOG_PAGE_SIZE),
|
||||
offset: Math.max(Math.trunc(requestedOffset), 0),
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user