From abf42a3476b03d7dba9db7c1d05e372ef8dfde42 Mon Sep 17 00:00:00 2001 From: mytlogos Date: Mon, 5 Sep 2022 16:09:57 +0200 Subject: [PATCH] feat: periodically delete used MediumInWaits --- packages/core/src/database/contexts/mediumInWaitContext.ts | 7 +++++++ packages/core/src/types.ts | 1 + packages/scraper/src/scheduler/scrapeJobs.ts | 6 ++++++ 3 files changed, 14 insertions(+) diff --git a/packages/core/src/database/contexts/mediumInWaitContext.ts b/packages/core/src/database/contexts/mediumInWaitContext.ts index a2652abd..96a7bacf 100644 --- a/packages/core/src/database/contexts/mediumInWaitContext.ts +++ b/packages/core/src/database/contexts/mediumInWaitContext.ts @@ -136,4 +136,11 @@ export class MediumInWaitContext extends SubContext { ); multiSingle(results, (result) => storeModifications("medium_in_wait", "insert", result)); } + + public async deleteUsedMediumInWait() { + const result = await this.dmlQuery( + "delete from medium_in_wait where (title, medium, link) in (select title, medium, link from medium_toc);", + ); + storeModifications("medium_in_wait", "delete", result); + } } diff --git a/packages/core/src/types.ts b/packages/core/src/types.ts index d6b21cff..cb24c029 100644 --- a/packages/core/src/types.ts +++ b/packages/core/src/types.ts @@ -1191,6 +1191,7 @@ export enum ScrapeName { queueTocs = "queueTocs", remapMediaParts = "remapMediaParts", queueExternalUser = "queueExternalUser", + removeUsedMediaInWaits = "removeUsedMediaInWaits", } export enum JobState { diff --git a/packages/scraper/src/scheduler/scrapeJobs.ts b/packages/scraper/src/scheduler/scrapeJobs.ts index f1d28e2a..972732b8 100644 --- a/packages/scraper/src/scheduler/scrapeJobs.ts +++ b/packages/scraper/src/scheduler/scrapeJobs.ts @@ -7,6 +7,7 @@ import { list } from "../jobs/oneTimeUser"; import { queueExternalUser } from "../jobs/queueExternalUser"; import { queueTocsJob } from "../jobs/queueTocs"; import { remapMediaParts } from "../jobs/remapMediumParts"; +import { removeUsedMediaInWaits } from "../jobs/removeUsedMediaInWaits"; import { searchForTocJob } from "../jobs/searchForToc"; import { toc, oneTimeToc } from "../jobs/toc"; @@ -21,6 +22,11 @@ export class ScrapeJob { public static readonly checkTocs = new ScrapeJob(ScrapeName.checkTocs, checkTocsJob); public static readonly queueTocs = new ScrapeJob(ScrapeName.queueTocs, queueTocsJob); public static readonly remapMediaParts = new ScrapeJob(ScrapeName.remapMediaParts, remapMediaParts); + public static readonly removeUsedMediaInWaits = new ScrapeJob( + ScrapeName.removeUsedMediaInWaits, + removeUsedMediaInWaits, + ); + public static readonly queueExternalUser = new ScrapeJob(ScrapeName.queueExternalUser, queueExternalUser); private constructor(