Fixed mass deletion page size. (#6275)
Fixed when page size was not the same as the one used for calculating number of pages
This commit is contained in:
@ -34,20 +34,20 @@ export const thirdRequestLastCursor = peopleMockWithIdsOnly.edges[mockPageSize *
|
||||
|
||||
export const variablesFirstRequest = {
|
||||
filter: undefined,
|
||||
limit: undefined,
|
||||
limit: mockPageSize,
|
||||
orderBy: undefined
|
||||
};
|
||||
|
||||
export const variablesSecondRequest = {
|
||||
filter: undefined,
|
||||
limit: undefined,
|
||||
limit: mockPageSize,
|
||||
orderBy: undefined,
|
||||
lastCursor: firstRequestLastCursor
|
||||
};
|
||||
|
||||
export const variablesThirdRequest = {
|
||||
filter: undefined,
|
||||
limit: undefined,
|
||||
limit: mockPageSize,
|
||||
orderBy: undefined,
|
||||
lastCursor: secondRequestLastCursor
|
||||
}
|
||||
|
||||
@ -1,12 +1,14 @@
|
||||
import { useApolloClient } from '@apollo/client';
|
||||
|
||||
import { triggerDeleteRecordsOptimisticEffect } from '@/apollo/optimistic-effect/utils/triggerDeleteRecordsOptimisticEffect';
|
||||
import { apiConfigState } from '@/client-config/states/apiConfigState';
|
||||
import { useObjectMetadataItem } from '@/object-metadata/hooks/useObjectMetadataItem';
|
||||
import { useObjectMetadataItems } from '@/object-metadata/hooks/useObjectMetadataItems';
|
||||
import { useGetRecordFromCache } from '@/object-record/cache/hooks/useGetRecordFromCache';
|
||||
import { DEFAULT_MUTATION_BATCH_SIZE } from '@/object-record/constants/DefaultMutationBatchSize';
|
||||
import { useDeleteManyRecordsMutation } from '@/object-record/hooks/useDeleteManyRecordsMutation';
|
||||
import { getDeleteManyRecordsMutationResponseField } from '@/object-record/utils/getDeleteManyRecordsMutationResponseField';
|
||||
import { useRecoilValue } from 'recoil';
|
||||
import { isDefined } from '~/utils/isDefined';
|
||||
import { sleep } from '~/utils/sleep';
|
||||
import { capitalize } from '~/utils/string/capitalize';
|
||||
@ -24,6 +26,11 @@ type DeleteManyRecordsOptions = {
|
||||
export const useDeleteManyRecords = ({
|
||||
objectNameSingular,
|
||||
}: useDeleteOneRecordProps) => {
|
||||
const apiConfig = useRecoilValue(apiConfigState);
|
||||
|
||||
const mutationPageSize =
|
||||
apiConfig?.mutationMaximumAffectedRecords ?? DEFAULT_MUTATION_BATCH_SIZE;
|
||||
|
||||
const apolloClient = useApolloClient();
|
||||
|
||||
const { objectMetadataItem } = useObjectMetadataItem({
|
||||
@ -48,16 +55,14 @@ export const useDeleteManyRecords = ({
|
||||
idsToDelete: string[],
|
||||
options?: DeleteManyRecordsOptions,
|
||||
) => {
|
||||
const numberOfBatches = Math.ceil(
|
||||
idsToDelete.length / DEFAULT_MUTATION_BATCH_SIZE,
|
||||
);
|
||||
const numberOfBatches = Math.ceil(idsToDelete.length / mutationPageSize);
|
||||
|
||||
const deletedRecords = [];
|
||||
|
||||
for (let batchIndex = 0; batchIndex < numberOfBatches; batchIndex++) {
|
||||
const batchIds = idsToDelete.slice(
|
||||
batchIndex * DEFAULT_MUTATION_BATCH_SIZE,
|
||||
(batchIndex + 1) * DEFAULT_MUTATION_BATCH_SIZE,
|
||||
batchIndex * mutationPageSize,
|
||||
(batchIndex + 1) * mutationPageSize,
|
||||
);
|
||||
|
||||
const deletedRecordsResponse = await apolloClient.mutate({
|
||||
|
||||
@ -20,6 +20,7 @@ export const useFetchAllRecordIds = <T>({
|
||||
objectNameSingular,
|
||||
filter,
|
||||
orderBy,
|
||||
limit: pageSize,
|
||||
recordGqlFields: { id: true },
|
||||
});
|
||||
|
||||
@ -49,12 +50,17 @@ export const useFetchAllRecordIds = <T>({
|
||||
|
||||
const remainingPages = Math.ceil(remainingCount / pageSize);
|
||||
|
||||
let lastCursor = firstQueryResult?.pageInfo.endCursor ?? '';
|
||||
let lastCursor = firstQueryResult?.pageInfo.endCursor ?? null;
|
||||
|
||||
for (let pageIndex = 0; pageIndex < remainingPages; pageIndex++) {
|
||||
if (lastCursor === null) {
|
||||
break;
|
||||
}
|
||||
|
||||
for (let i = 0; i < remainingPages; i++) {
|
||||
const rawResult = await fetchMore?.({
|
||||
variables: {
|
||||
lastCursor: lastCursor,
|
||||
limit: pageSize,
|
||||
},
|
||||
});
|
||||
|
||||
@ -64,7 +70,11 @@ export const useFetchAllRecordIds = <T>({
|
||||
recordIdSet.add(edge.node.id);
|
||||
}
|
||||
|
||||
lastCursor = fetchMoreResult.pageInfo.endCursor ?? '';
|
||||
if (fetchMoreResult.pageInfo.hasNextPage === false) {
|
||||
break;
|
||||
}
|
||||
|
||||
lastCursor = fetchMoreResult.pageInfo.endCursor ?? null;
|
||||
}
|
||||
|
||||
const recordIds = Array.from(recordIdSet);
|
||||
|
||||
Reference in New Issue
Block a user