Skip to content

Commit

Permalink
add concurrency
Browse files Browse the repository at this point in the history
  • Loading branch information
aubin-tchoi committed Jan 8, 2025
1 parent 3497166 commit 5549151
Showing 1 changed file with 19 additions and 15 deletions.
34 changes: 19 additions & 15 deletions front/migrations/20250108_backfill_folder_parents.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CoreAPI } from "@dust-tt/types";
import { concurrentExecutor, CoreAPI } from "@dust-tt/types";
import { Op, QueryTypes } from "sequelize";

import config from "@app/lib/api/config";
Expand All @@ -9,6 +9,7 @@ import { makeScript } from "@app/scripts/helpers";

const coreSequelize = getCoreReplicaDbConnection();
const DATASOURCE_BATCH_SIZE = 25;
const NODE_CONCURRENCY = 10;

async function migrateNode(
node: any,
Expand Down Expand Up @@ -63,20 +64,23 @@ async function migrateFolderDataSourceParents(
`SELECT node_id, parents, timestamp FROM data_sources_nodes WHERE data_source=:c`,
{ replacements: { c: coreDataSource.id }, type: QueryTypes.SELECT }
);
for (const node of nodes) {
await migrateNode(
node,
coreAPI,
dustAPIProjectId,
dustAPIDataSourceId,
execute,
logger.child({
nodeId: node.node_id,
parents: node.parents,
timestamp: new Date(node.timestamp),
})
);
}
await concurrentExecutor(
nodes,
async (node) =>
migrateNode(
node,
coreAPI,
dustAPIProjectId,
dustAPIDataSourceId,
execute,
logger.child({
nodeId: node.node_id,
parents: node.parents,
timestamp: new Date(node.timestamp),
})
),
{ concurrency: NODE_CONCURRENCY }
);
}

async function migrateFolderDataSourcesParents(
Expand Down

0 comments on commit 5549151

Please sign in to comment.