Skip to content

Commit

Permalink
query for Executions only when ids are actually needed for pruning bi…
Browse files Browse the repository at this point in the history
…nary data

in default mode the binary data is in the database, and will get pruned along with the executions.
  • Loading branch information
netroy committed Jan 5, 2023
1 parent 4461506 commit f39fe7c
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions packages/cli/src/WorkflowExecuteAdditionalData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ import * as WorkflowHelpers from '@/WorkflowHelpers';
import { getWorkflowOwner } from '@/UserManagement/UserManagementHelper';
import { findSubworkflowStart } from '@/utils';
import { PermissionChecker } from './UserManagement/PermissionChecker';
import { eventBus } from './eventbus';
import { WorkflowsService } from './workflows/workflows.services';

const ERROR_TRIGGER_TYPE = config.getEnv('nodes.errorTriggerType');
Expand Down Expand Up @@ -204,21 +203,24 @@ async function pruneExecutionData(this: WorkflowHooks): Promise<void> {
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
const utcDate = DateUtils.mixedDateToUtcDatetimeString(date);

const toPrune = { stoppedAt: LessThanOrEqual(utcDate) };
const isBinaryModeDefaultMode = config.getEnv('binaryDataManager.mode') === 'default';
try {
const executions = await Db.collections.Execution.find({
select: ['id'],
where: {
stoppedAt: LessThanOrEqual(utcDate),
},
});
await Db.collections.Execution.delete({ stoppedAt: LessThanOrEqual(utcDate) });
const executions = isBinaryModeDefaultMode
? []
: await Db.collections.Execution.find({
select: ['id'],
where: toPrune,
});
await Db.collections.Execution.delete(toPrune);
setTimeout(() => {
throttling = false;
}, timeout * 1000);
// Mark binary data for deletion for all executions
await BinaryDataManager.getInstance().markDataForDeletionByExecutionIds(
executions.map(({ id }) => id),
);
if (!isBinaryModeDefaultMode)
await BinaryDataManager.getInstance().markDataForDeletionByExecutionIds(
executions.map(({ id }) => id),
);
} catch (error) {
ErrorReporter.error(error);
throttling = false;
Expand Down

0 comments on commit f39fe7c

Please sign in to comment.