Delete rows in chunks
This commit is contained in:
@@ -55,11 +55,17 @@ const DeleteDatasetEntriesModal = ({ disclosure }: { disclosure: UseDisclosureRe
|
|||||||
|
|
||||||
const [deleteRows, deletionInProgress] = useHandledAsyncCallback(async () => {
|
const [deleteRows, deletionInProgress] = useHandledAsyncCallback(async () => {
|
||||||
if (!dataset?.id || !selectedIds.size) return;
|
if (!dataset?.id || !selectedIds.size) return;
|
||||||
|
|
||||||
|
// divide selectedIds into chunks of 15000 to reduce request size
|
||||||
|
const chunkSize = 15000;
|
||||||
|
const idsArray = Array.from(selectedIds);
|
||||||
|
for (let i = 0; i < idsArray.length; i += chunkSize) {
|
||||||
const response = await deleteRowsMutation.mutateAsync({
|
const response = await deleteRowsMutation.mutateAsync({
|
||||||
ids: Array.from(selectedIds),
|
ids: idsArray.slice(i, i + chunkSize),
|
||||||
});
|
});
|
||||||
|
|
||||||
if (maybeReportError(response)) return;
|
if (maybeReportError(response)) return;
|
||||||
|
}
|
||||||
|
|
||||||
await utils.datasetEntries.list.invalidate();
|
await utils.datasetEntries.list.invalidate();
|
||||||
disclosure.onClose();
|
disclosure.onClose();
|
||||||
|
|||||||
@@ -10,9 +10,10 @@ import {
|
|||||||
useDisclosure,
|
useDisclosure,
|
||||||
} from "@chakra-ui/react";
|
} from "@chakra-ui/react";
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
|
|
||||||
import { useState, useEffect } from "react";
|
import { useState, useEffect } from "react";
|
||||||
import { AiOutlineDatabase } from "react-icons/ai";
|
import { AiOutlineDatabase } from "react-icons/ai";
|
||||||
|
|
||||||
|
import { env } from "~/env.mjs";
|
||||||
import AppShell from "~/components/nav/AppShell";
|
import AppShell from "~/components/nav/AppShell";
|
||||||
import { api } from "~/utils/api";
|
import { api } from "~/utils/api";
|
||||||
import { useDataset, useHandledAsyncCallback } from "~/utils/hooks";
|
import { useDataset, useHandledAsyncCallback } from "~/utils/hooks";
|
||||||
@@ -126,7 +127,7 @@ export default function Dataset() {
|
|||||||
<FineTuneButton />
|
<FineTuneButton />
|
||||||
<ImportDataButton />
|
<ImportDataButton />
|
||||||
<ExperimentButton />
|
<ExperimentButton />
|
||||||
<DownloadButton />
|
{/* <DownloadButton /> */}
|
||||||
<DeleteButton />
|
<DeleteButton />
|
||||||
</HStack>
|
</HStack>
|
||||||
<DatasetEntriesTable />
|
<DatasetEntriesTable />
|
||||||
|
|||||||
Reference in New Issue
Block a user