From 4fe7752f3cd9d52b97d212afc49fc46c60d318d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damir=20Jeli=C4=87?= Date: Tue, 26 Nov 2019 13:37:07 +0100 Subject: [PATCH] EventIndex: Add a method to gather the currently crawled rooms. --- src/indexing/EventIndex.js | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/indexing/EventIndex.js b/src/indexing/EventIndex.js index c907e769b5..1b17cc6d87 100644 --- a/src/indexing/EventIndex.js +++ b/src/indexing/EventIndex.js @@ -33,6 +33,7 @@ export default class EventIndex { // crawl. this._eventsPerCrawl = 100; this._crawler = null; + this._currentCheckpoint = null; this.liveEventsForIndex = new Set(); } @@ -213,6 +214,8 @@ export default class EventIndex { sleepTime = this._crawlerIdleTime; } + this._currentCheckpoint = null; + await sleep(sleepTime); console.log("EventIndex: Running the crawler loop."); @@ -230,6 +233,8 @@ export default class EventIndex { continue; } + this._currentCheckpoint = checkpoint; + idle = false; console.log("EventIndex: crawling using checkpoint", checkpoint); @@ -424,4 +429,31 @@ export default class EventIndex { const indexManager = PlatformPeg.get().getEventIndexingManager(); return indexManager.indexSize(); } + + currentlyCrawledRooms() { + let crawlingRooms = new Set(); + let totalRooms = new Set(); + + this.crawlerCheckpoints.forEach((checkpoint, index) => { + crawlingRooms.add(checkpoint.roomId); + }); + + if (this._currentCheckpoint !== null) { + crawlingRooms.add(this._currentCheckpoint.roomId); + } + + const client = MatrixClientPeg.get(); + const rooms = client.getRooms(); + + const isRoomEncrypted = (room) => { + return client.isRoomEncrypted(room.roomId); + }; + + const encryptedRooms = rooms.filter(isRoomEncrypted); + encryptedRooms.forEach((room, index) => { + totalRooms.add(room.roomId); + }); + + return {crawlingRooms, totalRooms} + } }