Skip to content

Commit

Permalink
server-esm: Fix cyclical dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
eliandoran committed Jul 18, 2024
1 parent b6c5880 commit 87fbd4b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
3 changes: 3 additions & 0 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import assets from "./routes/assets.js";
import routes from "./routes/routes.js";
import custom from "./routes/custom.js";
import error_handlers from "./routes/error_handlers.js";
import { startScheduledCleanup } from "./services/erase.js";

await import('./services/handlers');
await import('./becca/becca_loader');
Expand Down Expand Up @@ -61,6 +62,8 @@ await import('./services/consistency_checks');

await import('./services/scheduler');

startScheduledCleanup();

if (utils.isElectron()) {
(await import('@electron/remote/main')).initialize();
}
Expand Down
20 changes: 11 additions & 9 deletions src/services/erase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,20 +177,22 @@ function eraseScheduledAttachments(eraseUnusedAttachmentsAfterSeconds: number |
eraseAttachments(attachmentIdsToErase);
}

sqlInit.dbReady.then(() => {
// first cleanup kickoff 5 minutes after startup
setTimeout(cls.wrap(() => eraseDeletedEntities()), 5 * 60 * 1000);
setTimeout(cls.wrap(() => eraseScheduledAttachments()), 6 * 60 * 1000);

setInterval(cls.wrap(() => eraseDeletedEntities()), 4 * 3600 * 1000);
setInterval(cls.wrap(() => eraseScheduledAttachments()), 3600 * 1000);
});
export function startScheduledCleanup() {
sqlInit.dbReady.then(() => {
// first cleanup kickoff 5 minutes after startup
setTimeout(cls.wrap(() => eraseDeletedEntities()), 5 * 60 * 1000);
setTimeout(cls.wrap(() => eraseScheduledAttachments()), 6 * 60 * 1000);

setInterval(cls.wrap(() => eraseDeletedEntities()), 4 * 3600 * 1000);
setInterval(cls.wrap(() => eraseScheduledAttachments()), 3600 * 1000);
});
}

export default {
eraseDeletedNotesNow,
eraseUnusedAttachmentsNow,
eraseNotesWithDeleteId,
eraseUnusedBlobs,
eraseAttachments,
eraseRevisions
eraseRevisions,
};

0 comments on commit 87fbd4b

Please sign in to comment.