diff --git a/client/data/mq.datastore.ts b/client/data/mq.datastore.ts index 6b96f171..b43b359d 100644 --- a/client/data/mq.datastore.ts +++ b/client/data/mq.datastore.ts @@ -356,6 +356,13 @@ export class DataStoreMQ { await this.ds.batchDelete(ids); } + /** + * Flushes all queues + */ + flushAllQueues() { + return this.ds.batchDeletePrefix(["mq"]); + } + async getQueueStats(queue?: string): Promise { const queued = await this.ds.kv.countQuery({ prefix: queue ? [...queuedPrefix, queue] : queuedPrefix, diff --git a/client/plugos/syscalls/mq.ts b/client/plugos/syscalls/mq.ts index 9472249a..18a7f418 100644 --- a/client/plugos/syscalls/mq.ts +++ b/client/plugos/syscalls/mq.ts @@ -39,6 +39,9 @@ export function mqSyscalls( "mq.flushQueue": (_ctx, queue: string) => { return mq.flushQueue(queue); }, + "mq.flushAllQueues": () => { + return mq.flushAllQueues(); + }, "mq.getQueueStats": (_ctx, queue: string) => { return mq.getQueueStats(queue); }, diff --git a/plug-api/syscalls/mq.ts b/plug-api/syscalls/mq.ts index 540300d1..5577bd6d 100644 --- a/plug-api/syscalls/mq.ts +++ b/plug-api/syscalls/mq.ts @@ -36,6 +36,13 @@ export function flushQueue(queue: string): Promise { return syscall("mq.flushQueue", queue); } +/** + * Flushes all messages from all queues. + */ +export function flushAllQueues(): Promise { + return syscall("mq.flushAllQueues"); +} + /** * Acknowledges a message from a queue, in case it needs to be explicitly acknowledged. * @param queue the name of the queue the message came from diff --git a/plugs/editor/system.ts b/plugs/editor/system.ts index 8eb0ca76..c71cb479 100644 --- a/plugs/editor/system.ts +++ b/plugs/editor/system.ts @@ -1,6 +1,7 @@ import { editor, markdown, + mq, system, } from "@silverbulletmd/silverbullet/syscalls"; @@ -30,7 +31,13 @@ export async function wipeAndLogoutCommand() { await system.wipeClient(true); } +/** + * Does the following: + * - Flushes all message queues + * - Cleans IndexedDB databases not connected to the current space + */ export async function cleanClientCommand() { + await mq.flushAllQueues(); if (await system.cleanDatabases()) { await editor.alert("Successfullly cleaned unnecessary client databases."); } else {