mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-08 19:28:16 +00:00
Improve FolderTreeCheckpointResources migration handling
This commit is contained in:
@@ -226,7 +226,7 @@ export async function up(knex: Knex): Promise<void> {
|
|||||||
// Insert New Commits in batches of 9000
|
// Insert New Commits in batches of 9000
|
||||||
const newCommits = foldersCommitsList.map((folderCommit) => folderCommit.commit);
|
const newCommits = foldersCommitsList.map((folderCommit) => folderCommit.commit);
|
||||||
const commitBatches = chunkArray(newCommits, 9000);
|
const commitBatches = chunkArray(newCommits, 9000);
|
||||||
|
let pendingDeepTreeCommitResources: TFolderCommits[] = [];
|
||||||
let j = 0;
|
let j = 0;
|
||||||
for (const commitBatch of commitBatches) {
|
for (const commitBatch of commitBatches) {
|
||||||
j += 1;
|
j += 1;
|
||||||
@@ -322,20 +322,31 @@ export async function up(knex: Knex): Promise<void> {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Create Folder Tree Checkpoint Resources
|
// Create Folder Tree Checkpoint Resources
|
||||||
|
const commitsToProcess = pendingDeepTreeCommitResources.concat(newCommitsInserted);
|
||||||
|
const unprocessableCommits: TFolderCommits[] = [];
|
||||||
|
const processableCommits = commitsToProcess.filter((folderCommit) => {
|
||||||
|
const isProcessable = newTreeCheckpointsMap[folderCommit.envId];
|
||||||
|
if (!isProcessable) {
|
||||||
|
unprocessableCommits.push(folderCommit);
|
||||||
|
}
|
||||||
|
return isProcessable;
|
||||||
|
});
|
||||||
|
|
||||||
|
if (processableCommits.length > 0) {
|
||||||
// eslint-disable-next-line no-await-in-loop
|
// eslint-disable-next-line no-await-in-loop
|
||||||
await knex
|
await knex
|
||||||
.batchInsert(
|
.batchInsert(
|
||||||
TableName.FolderTreeCheckpointResources,
|
TableName.FolderTreeCheckpointResources,
|
||||||
newCommitsInserted
|
processableCommits.map((folderCommit) => ({
|
||||||
.filter((folderCommit) => newTreeCheckpointsMap[folderCommit.envId])
|
|
||||||
.map((folderCommit) => ({
|
|
||||||
folderTreeCheckpointId: newTreeCheckpointsMap[folderCommit.envId],
|
folderTreeCheckpointId: newTreeCheckpointsMap[folderCommit.envId],
|
||||||
folderId: folderCommit.folderId,
|
folderId: folderCommit.folderId,
|
||||||
folderCommitId: folderCommit.id
|
folderCommitId: folderCommit.id
|
||||||
}))
|
}))
|
||||||
)
|
)
|
||||||
.returning("*");
|
.returning("*");
|
||||||
|
}
|
||||||
|
|
||||||
|
pendingDeepTreeCommitResources = unprocessableCommits;
|
||||||
logger.info(`Finished inserting folder tree checkpoint resources - batch ${j} of ${commitBatches.length}`);
|
logger.info(`Finished inserting folder tree checkpoint resources - batch ${j} of ${commitBatches.length}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user