diff --git a/packages/server/src/api/controllers/automation.js b/packages/server/src/api/controllers/automation.js index 4b273fe49d..b4dd852273 100644 --- a/packages/server/src/api/controllers/automation.js +++ b/packages/server/src/api/controllers/automation.js @@ -21,6 +21,7 @@ const { const { events } = require("@budibase/backend-core") const { app } = require("@budibase/backend-core/cache") const { logs } = require("@budibase/pro") +const { clearOldHistory } = require("../../automations/logging") const ACTION_DEFS = removeDeprecated(actions.ACTION_DEFINITIONS) const TRIGGER_DEFS = removeDeprecated(triggers.TRIGGER_DEFINITIONS) @@ -195,6 +196,8 @@ exports.destroy = async function (ctx) { exports.logSearch = async function (ctx) { let { automationId, status, page, startDate } = ctx.request.body + // before querying logs, make sure old logs are cleared out + await clearOldHistory() ctx.body = await logs.automations.getLogs( startDate, status, diff --git a/packages/server/src/automations/logging/index.ts b/packages/server/src/automations/logging/index.ts index 3372726918..c91d2e4950 100644 --- a/packages/server/src/automations/logging/index.ts +++ b/packages/server/src/automations/logging/index.ts @@ -32,7 +32,7 @@ function getStatus(results: AutomationResults) { return status } -async function clearOldHistory() { +export async function clearOldHistory() { const db = getProdAppDB() try { const expired = await logs.automations.getExpiredLogs()