fix: update current cursor (#17626)

This commit is contained in:
Udit Takkar
2024-11-15 16:07:17 -07:00
committed by GitHub
parent 6272c881c8
commit 8962f6f08e
@@ -46,25 +46,26 @@ export const getEventTypesFromGroup = async ({
!isFilterSet || isUpIdInFilter || (isFilterSet && filters?.upIds && !isUpIdInFilter);
const eventTypes: MappedEventType[] = [];
const currentCursor = cursor;
let nextCursor: number | null | undefined = undefined;
let isFetchingForFirstTime = true;
let paginationCursor = cursor;
let hasMoreResults = true;
let isFirstFetch = true;
const fetchAndFilterEventTypes = async () => {
const batch = await fetchEventTypesBatch(ctx, input, shouldListUserEvents, currentCursor, searchQuery);
const batch = await fetchEventTypesBatch(ctx, input, shouldListUserEvents, paginationCursor, searchQuery);
const filteredBatch = await filterEventTypes(batch.eventTypes, ctx.user.id, shouldListUserEvents, teamId);
eventTypes.push(...filteredBatch);
nextCursor = batch.nextCursor;
paginationCursor = batch.nextCursor;
hasMoreResults = !!batch.nextCursor;
};
while (eventTypes.length < limit && (nextCursor || isFetchingForFirstTime)) {
while (eventTypes.length < limit && (hasMoreResults || isFirstFetch)) {
await fetchAndFilterEventTypes();
isFetchingForFirstTime = false;
isFirstFetch = false;
}
return {
eventTypes,
nextCursor: nextCursor ?? undefined,
nextCursor: paginationCursor ?? undefined,
};
};