From 1b9b30d4ea735798f344d4fbc36655d4f1ff6950 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damir=20Jeli=C4=87?= Date: Mon, 20 Jan 2020 17:42:24 +0100 Subject: [PATCH] EventIndexPanel: Get more stats for our indexer, not just the size. --- .../views/settings/EventIndexPanel.js | 40 +++++++++++++------ src/i18n/strings/en_EN.json | 18 +++++---- src/indexing/BaseEventIndexManager.js | 13 +++++- src/indexing/EventIndex.js | 27 ++++++++++++- 4 files changed, 74 insertions(+), 24 deletions(-) diff --git a/src/components/views/settings/EventIndexPanel.js b/src/components/views/settings/EventIndexPanel.js index bade2d8735..f8c61e092d 100644 --- a/src/components/views/settings/EventIndexPanel.js +++ b/src/components/views/settings/EventIndexPanel.js @@ -35,6 +35,9 @@ export default class EventIndexPanel extends React.Component { eventIndexSize: 0, crawlingRooms: 0, totalCrawlingRooms: 0, + eventCount: 0, + roomCount: 0, + currentRoom: null, eventIndexingEnabled: SettingsStore.getValueAt(SettingLevel.DEVICE, 'enableCrawling'), crawlerSleepTime: @@ -44,22 +47,35 @@ export default class EventIndexPanel extends React.Component { async componentWillMount(): void { let eventIndexSize = 0; + let roomCount = 0; + let eventCount = 0; let crawlingRooms = 0; let totalCrawlingRooms = 0; + let currentRoom = null; const eventIndex = EventIndexPeg.get(); if (eventIndex !== null) { - eventIndexSize = await eventIndex.indexSize(); + const stats = await eventIndex.getStats(); + eventIndexSize = stats.size; + roomCount = stats.roomCount; + eventCount = stats.eventCount; + const crawledRooms = eventIndex.currentlyCrawledRooms(); crawlingRooms = crawledRooms.crawlingRooms.size; totalCrawlingRooms = crawledRooms.totalRooms.size; + + const room = eventIndex.currentRoom(); + if (room) currentRoom = room.name; } this.setState({ eventIndexSize, crawlingRooms, totalCrawlingRooms, + eventCount, + roomCount, + currentRoom, }); } @@ -82,16 +98,15 @@ export default class EventIndexPanel extends React.Component { let crawlerState; if (!this.state.eventIndexingEnabled) { - crawlerState =
{_t("Message downloader is stopped.")}
; - } else if (this.state.crawlingRooms === 0) { - crawlerState =
{_t("Message downloader is currently idle.")}
; + crawlerState =
{_t("Message search for encrypted rooms is disabled.")}
; + } else if (this.state.currentRoom === null) { + crawlerState =
{_t("Not currently downloading messages for any room.")}
; } else { crawlerState = (
{_t( - "Currently downloading mesages in %(crawlingRooms)s of %(totalRooms)s rooms.", - { crawlingRooms: this.state.crawlingRooms, - totalRooms: this.state.totalCrawlingRooms, - })} + "Downloading mesages for %(currentRoom)s.", + { currentRoom: this.state.currentRoom } + )}
); } @@ -101,13 +116,14 @@ export default class EventIndexPanel extends React.Component {
{_t("Encrypted search")} { - _t( "To enable search in encrypted rooms, Riot needs to run " + - "a background process to download historical messages " + - "from those rooms to your computer.", + _t( "Riot is securely caching encrypted messages locally for them" + + "to appear in search results:" ) }
- {_t("Message disk usage:")} {formatBytes(this.state.eventIndexSize, 0)}
+ {_t("Space used:")} {formatBytes(this.state.eventIndexSize, 0)}
+ {_t("Indexed messages:")} {this.state.eventCount}
+ {_t("Number of rooms:")} {this.state.roomCount}
{crawlerState}
diff --git a/src/i18n/strings/en_EN.json b/src/i18n/strings/en_EN.json index 1d1636bfb2..a968c145d9 100644 --- a/src/i18n/strings/en_EN.json +++ b/src/i18n/strings/en_EN.json @@ -554,6 +554,16 @@ "Failed to set display name": "Failed to set display name", "Disable Notifications": "Disable Notifications", "Enable Notifications": "Enable Notifications", + "Message search for encrypted rooms is disabled.": "Message search for encrypted rooms is disabled.", + "Not currently downloading messages for any room.": "Not currently downloading messages for any room.", + "Downloading mesages for %(currentRoom)s.": "Downloading mesages for %(currentRoom)s.", + "Encrypted search": "Encrypted search", + "Riot is securely caching encrypted messages locally for themto appear in search results:": "Riot is securely caching encrypted messages locally for themto appear in search results:", + "Space used:": "Space used:", + "Indexed messages:": "Indexed messages:", + "Number of rooms:": "Number of rooms:", + "Download and index encrypted messages": "Download and index encrypted messages", + "Message downloading sleep time(ms)": "Message downloading sleep time(ms)", "Connecting to integration manager...": "Connecting to integration manager...", "Cannot connect to integration manager": "Cannot connect to integration manager", "The integration manager is offline or it cannot reach your homeserver.": "The integration manager is offline or it cannot reach your homeserver.", @@ -732,14 +742,6 @@ "Start automatically after system login": "Start automatically after system login", "Always show the window menu bar": "Always show the window menu bar", "Show tray icon and minimize window to it on close": "Show tray icon and minimize window to it on close", - "Message downloader is stopped.": "Message downloader is stopped.", - "Message downloader is currently idle.": "Message downloader is currently idle.", - "Currently downloading mesages in %(crawlingRooms)s of %(totalRooms)s rooms.": "Currently downloading mesages in %(crawlingRooms)s of %(totalRooms)s rooms.", - "Encrypted search": "Encrypted search", - "To enable search in encrypted rooms, Riot needs to run a background process to download historical messages from those rooms to your computer.": "To enable search in encrypted rooms, Riot needs to run a background process to download historical messages from those rooms to your computer.", - "Message disk usage:": "Message disk usage:", - "Download and index encrypted messages": "Download and index encrypted messages", - "Message downloading sleep time(ms)": "Message downloading sleep time(ms)", "Preferences": "Preferences", "Composer": "Composer", "Timeline": "Timeline", diff --git a/src/indexing/BaseEventIndexManager.js b/src/indexing/BaseEventIndexManager.js index 733dc05dd6..819b3e65a7 100644 --- a/src/indexing/BaseEventIndexManager.js +++ b/src/indexing/BaseEventIndexManager.js @@ -67,6 +67,12 @@ export interface HistoricEvent { profile: MatrixProfile; } +export interface IndexStats { + size: number; + event_count: number; + room_count: number; +} + /** * Base class for classes that provide platform-specific event indexing. * @@ -118,9 +124,12 @@ export default class BaseEventIndexManager { } /** - * Get the disk usage of the index + * Get statistical information of the index. + * + * @return {Promise} A promise that will resolve to the index + * statistics. */ - async indexSize(): Promise { + async getStats(): Promise { throw new Error("Unimplemented"); } diff --git a/src/indexing/EventIndex.js b/src/indexing/EventIndex.js index 0d7f43b839..d00a0530ba 100644 --- a/src/indexing/EventIndex.js +++ b/src/indexing/EventIndex.js @@ -425,9 +425,9 @@ export default class EventIndex { return indexManager.searchEventIndex(searchArgs); } - async indexSize() { + async getStats() { const indexManager = PlatformPeg.get().getEventIndexingManager(); - return indexManager.indexSize(); + return indexManager.getStats(); } currentlyCrawledRooms() { @@ -456,4 +456,27 @@ export default class EventIndex { return {crawlingRooms, totalRooms}; } + + /** + * Get the room that we are currently crawling. + * + * @returns A MatrixRoom that is being currently crawled, null if no room is + * currently being crawled. + */ + currentRoom() { + if (this._currentCheckpoint === null && this.crawlerCheckpoints.length === 0) { + console.log("EventIndex: No current nor any checkpoint"); + return null; + } + + const client = MatrixClientPeg.get(); + + if (this._currentCheckpoint !== null) { + console.log("EventIndex: Current checkpoint available"); + return client.getRoom(this._currentCheckpoint.roomId); + } else { + console.log("EventIndex: No current but have checkpoint available"); + return client.getRoom(this.crawlerCheckpoints[0].roomId); + } + } }