diff --git a/src/db/roomstore.ts b/src/db/roomstore.ts index 87ceea708c5b12b4315ba947b7ed304b5496a682..a3068c8ee4d11134d2780880dfb7960054e7c7cc 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>[] = [];