From 99f3aa0db5762fbf458e7f0c63e89de4195447a5 Mon Sep 17 00:00:00 2001 From: Christian Paul <christianp@matrix.org> Date: Mon, 4 Jan 2021 20:26:14 +0100 Subject: [PATCH] Add countEntries --- src/db/roomstore.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/db/roomstore.ts b/src/db/roomstore.ts index 87ceea7..a3068c8 100644 --- a/src/db/roomstore.ts +++ b/src/db/roomstore.ts @@ -98,6 +98,22 @@ export class DbRoomStore { this.entriesMatrixIdCache = new TimedCache(ENTRY_CACHE_LIMETIME); } + /** + * Returns the number of bridged room pairs. Every connection between a + * Matrix room and a remote room counts as one pair. + * @returns {number} The amount of room pairs as an integer + */ + public async countEntries() { + const row = (await this.db.Get("SELECT COUNT(*) FROM room_entries")) || {}; + + if (typeof row.count !== "number") { + log.error("Failed to count room entries"); + throw Error("Failed to count room entries"); + } + + return row.count; + } + public async upsertEntry(entry: IRoomStoreEntry) { const promises: Promise<void>[] = []; -- GitLab