EventIndexPanel: Get more stats for our indexer, not just the size.

This commit is contained in:
Damir Jelić 2020-01-20 17:42:24 +01:00
parent 695b8aff5b
commit 1b9b30d4ea
4 changed files with 74 additions and 24 deletions

View File

@ -35,6 +35,9 @@ export default class EventIndexPanel extends React.Component {
eventIndexSize: 0, eventIndexSize: 0,
crawlingRooms: 0, crawlingRooms: 0,
totalCrawlingRooms: 0, totalCrawlingRooms: 0,
eventCount: 0,
roomCount: 0,
currentRoom: null,
eventIndexingEnabled: eventIndexingEnabled:
SettingsStore.getValueAt(SettingLevel.DEVICE, 'enableCrawling'), SettingsStore.getValueAt(SettingLevel.DEVICE, 'enableCrawling'),
crawlerSleepTime: crawlerSleepTime:
@ -44,22 +47,35 @@ export default class EventIndexPanel extends React.Component {
async componentWillMount(): void { async componentWillMount(): void {
let eventIndexSize = 0; let eventIndexSize = 0;
let roomCount = 0;
let eventCount = 0;
let crawlingRooms = 0; let crawlingRooms = 0;
let totalCrawlingRooms = 0; let totalCrawlingRooms = 0;
let currentRoom = null;
const eventIndex = EventIndexPeg.get(); const eventIndex = EventIndexPeg.get();
if (eventIndex !== null) { 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(); const crawledRooms = eventIndex.currentlyCrawledRooms();
crawlingRooms = crawledRooms.crawlingRooms.size; crawlingRooms = crawledRooms.crawlingRooms.size;
totalCrawlingRooms = crawledRooms.totalRooms.size; totalCrawlingRooms = crawledRooms.totalRooms.size;
const room = eventIndex.currentRoom();
if (room) currentRoom = room.name;
} }
this.setState({ this.setState({
eventIndexSize, eventIndexSize,
crawlingRooms, crawlingRooms,
totalCrawlingRooms, totalCrawlingRooms,
eventCount,
roomCount,
currentRoom,
}); });
} }
@ -82,16 +98,15 @@ export default class EventIndexPanel extends React.Component {
let crawlerState; let crawlerState;
if (!this.state.eventIndexingEnabled) { if (!this.state.eventIndexingEnabled) {
crawlerState = <div>{_t("Message downloader is stopped.")}</div>; crawlerState = <div>{_t("Message search for encrypted rooms is disabled.")}</div>;
} else if (this.state.crawlingRooms === 0) { } else if (this.state.currentRoom === null) {
crawlerState = <div>{_t("Message downloader is currently idle.")}</div>; crawlerState = <div>{_t("Not currently downloading messages for any room.")}</div>;
} else { } else {
crawlerState = ( crawlerState = (
<div>{_t( <div>{_t(
"Currently downloading mesages in %(crawlingRooms)s of %(totalRooms)s rooms.", "Downloading mesages for %(currentRoom)s.",
{ crawlingRooms: this.state.crawlingRooms, { currentRoom: this.state.currentRoom }
totalRooms: this.state.totalCrawlingRooms, )}
})}
</div> </div>
); );
} }
@ -101,13 +116,14 @@ export default class EventIndexPanel extends React.Component {
<div className="mx_SettingsTab_section"> <div className="mx_SettingsTab_section">
<span className="mx_SettingsTab_subheading">{_t("Encrypted search")}</span> <span className="mx_SettingsTab_subheading">{_t("Encrypted search")}</span>
{ {
_t( "To enable search in encrypted rooms, Riot needs to run " + _t( "Riot is securely caching encrypted messages locally for them" +
"a background process to download historical messages " + "to appear in search results:"
"from those rooms to your computer.",
) )
} }
<div className='mx_SettingsTab_subsectionText'> <div className='mx_SettingsTab_subsectionText'>
{_t("Message disk usage:")} {formatBytes(this.state.eventIndexSize, 0)}<br /> {_t("Space used:")} {formatBytes(this.state.eventIndexSize, 0)}<br />
{_t("Indexed messages:")} {this.state.eventCount}<br />
{_t("Number of rooms:")} {this.state.roomCount}<br />
{crawlerState}<br /> {crawlerState}<br />
</div> </div>

View File

@ -554,6 +554,16 @@
"Failed to set display name": "Failed to set display name", "Failed to set display name": "Failed to set display name",
"Disable Notifications": "Disable Notifications", "Disable Notifications": "Disable Notifications",
"Enable Notifications": "Enable 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...", "Connecting to integration manager...": "Connecting to integration manager...",
"Cannot connect to integration manager": "Cannot connect 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.", "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", "Start automatically after system login": "Start automatically after system login",
"Always show the window menu bar": "Always show the window menu bar", "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", "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", "Preferences": "Preferences",
"Composer": "Composer", "Composer": "Composer",
"Timeline": "Timeline", "Timeline": "Timeline",

View File

@ -67,6 +67,12 @@ export interface HistoricEvent {
profile: MatrixProfile; profile: MatrixProfile;
} }
export interface IndexStats {
size: number;
event_count: number;
room_count: number;
}
/** /**
* Base class for classes that provide platform-specific event indexing. * 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<IndexStats>} A promise that will resolve to the index
* statistics.
*/ */
async indexSize(): Promise<number> { async getStats(): Promise<IndexStats> {
throw new Error("Unimplemented"); throw new Error("Unimplemented");
} }

View File

@ -425,9 +425,9 @@ export default class EventIndex {
return indexManager.searchEventIndex(searchArgs); return indexManager.searchEventIndex(searchArgs);
} }
async indexSize() { async getStats() {
const indexManager = PlatformPeg.get().getEventIndexingManager(); const indexManager = PlatformPeg.get().getEventIndexingManager();
return indexManager.indexSize(); return indexManager.getStats();
} }
currentlyCrawledRooms() { currentlyCrawledRooms() {
@ -456,4 +456,27 @@ export default class EventIndex {
return {crawlingRooms, totalRooms}; 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);
}
}
} }