mirror of
https://github.com/outline/outline.git
synced 2026-11-22 05:51:43 +03:00
* chore: Remove unused lint disable directives Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WJegM4QsoYSKrBKb6eB4CH * chore: Replace TODO type suppressions with typed code Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WJegM4QsoYSKrBKb6eB4CH * chore: Remove obsolete workaround comments in tests and MediaDimension Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WJegM4QsoYSKrBKb6eB4CH * chore: Remove Tippy compatibility props from Tooltip Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WJegM4QsoYSKrBKb6eB4CH * chore: Decouple DropdownMenu props from Tooltip and clarify sharing styles Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WJegM4QsoYSKrBKb6eB4CH * chore: Remove stale retention TODOs from cleanup tasks Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WJegM4QsoYSKrBKb6eB4CH * chore: Register relations synchronously and clarify workaround comments Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WJegM4QsoYSKrBKb6eB4CH * chore: Replace Notion import TODOs with descriptive comments Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WJegM4QsoYSKrBKb6eB4CH --------- Co-authored-by: Claude <noreply@anthropic.com>
68 lines
1.9 KiB
TypeScript
68 lines
1.9 KiB
TypeScript
import { subDays } from "date-fns";
|
|
import { Op } from "sequelize";
|
|
import Logger from "@server/logging/Logger";
|
|
import { SearchQuery } from "@server/models";
|
|
import { sequelizeReadOnly } from "@server/storage/database";
|
|
import { TaskPriority } from "./base/BaseTask";
|
|
import type { Props } from "./base/CronTask";
|
|
import { CronTask, TaskInterval } from "./base/CronTask";
|
|
import { Minute } from "@shared/utils/time";
|
|
|
|
export default class CleanupOldSearchQueriesTask extends CronTask {
|
|
public async perform({ partition }: Props) {
|
|
const retentionDays = 365;
|
|
const cutoffDate = subDays(new Date(), retentionDays);
|
|
const maxSearchQueriesPerTask = 100000;
|
|
let totalSearchQueriesDeleted = 0;
|
|
|
|
try {
|
|
await sequelizeReadOnly.transaction(async (transaction) =>
|
|
SearchQuery.findAllInBatches(
|
|
{
|
|
attributes: ["id"],
|
|
where: {
|
|
createdAt: {
|
|
[Op.lt]: cutoffDate,
|
|
},
|
|
...this.getPartitionWhereClause("id", partition),
|
|
},
|
|
batchLimit: 1000,
|
|
totalLimit: maxSearchQueriesPerTask,
|
|
order: [["createdAt", "ASC"]],
|
|
transaction,
|
|
},
|
|
async (searchQueries) => {
|
|
totalSearchQueriesDeleted += await SearchQuery.destroy({
|
|
where: {
|
|
id: {
|
|
[Op.in]: searchQueries.map((searchQuery) => searchQuery.id),
|
|
},
|
|
},
|
|
});
|
|
}
|
|
)
|
|
);
|
|
} finally {
|
|
if (totalSearchQueriesDeleted > 0) {
|
|
Logger.info("task", `Deleted old search queries`, {
|
|
totalSearchQueriesDeleted,
|
|
});
|
|
}
|
|
}
|
|
}
|
|
|
|
public get cron() {
|
|
return {
|
|
interval: TaskInterval.Hour,
|
|
partitionWindow: 15 * Minute.ms,
|
|
};
|
|
}
|
|
|
|
public get options() {
|
|
return {
|
|
attempts: 1,
|
|
priority: TaskPriority.Background,
|
|
};
|
|
}
|
|
}
|