MessageEventIndexDialog: distinguish indexed rooms (#31436)

* MessageEventIndexDialog: comments for state

* ManageEventIndexDialog: deduplicate some code

`updateCurrentRoom` has the same logic as `componentDidMount`, so let's factor
it out.

* ManageEventIndexDialog: distinguish indexed rooms

Just because a room is not currently awaiting indexing does not mean it has
been indexed. Update the dialog to show the actual number of indexed rooms, and
the number of rooms that are awaiting indexing.

* Apply suggestion from @richvdh

---------

Co-authored-by: Will Hunt <2072976+Half-Shot@users.noreply.github.com>
This commit is contained in:
Richard van der Hoff
2025-12-07 22:23:59 +00:00
committed by GitHub
co-authored by Will Hunt
parent 7887cbb81b
commit f0738a295a
2 changed files with 24 additions and 33 deletions
@@ -26,11 +26,25 @@ interface IProps {
}
interface IState {
/** Size of the event index, in bytes. */
eventIndexSize: number;
/** Number of events currently indexed in the event index. */
eventCount: number;
/** Number of rooms currently mentioned in the event index. */
eventIndexRoomCount: number;
/** Number of rooms awaiting crawling by the EventIndex. */
crawlingRoomsCount: number;
/** Number of encrypted rooms known by the MatrixClient. */
roomCount: number;
/** Room currently being crawled by the EventIndex. */
currentRoom: string | null;
/** Time to sleep between crawlwer passes, in milliseconds. */
crawlerSleepTime: number;
}
@@ -44,6 +58,7 @@ export default class ManageEventIndexDialog extends React.Component<IProps, ISta
this.state = {
eventIndexSize: 0,
eventCount: 0,
eventIndexRoomCount: 0,
crawlingRoomsCount: 0,
roomCount: 0,
currentRoom: null,
@@ -51,7 +66,7 @@ export default class ManageEventIndexDialog extends React.Component<IProps, ISta
};
}
public updateCurrentRoom = async (room: Room): Promise<void> => {
public updateCurrentRoom = async (room: Room | null): Promise<void> => {
const eventIndex = EventIndexPeg.get();
if (!eventIndex) return;
let stats: IIndexStats | undefined;
@@ -74,6 +89,7 @@ export default class ManageEventIndexDialog extends React.Component<IProps, ISta
this.setState({
eventIndexSize: stats?.size ?? 0,
eventCount: stats?.eventCount ?? 0,
eventIndexRoomCount: stats?.roomCount ?? 0,
crawlingRoomsCount: crawlingRoomsCount,
roomCount: roomCount,
currentRoom: currentRoom,
@@ -89,44 +105,14 @@ export default class ManageEventIndexDialog extends React.Component<IProps, ISta
}
public async componentDidMount(): Promise<void> {
let eventIndexSize = 0;
let crawlingRoomsCount = 0;
let roomCount = 0;
let eventCount = 0;
let currentRoom: string | null = null;
const eventIndex = EventIndexPeg.get();
if (eventIndex !== null) {
eventIndex.on("changedCheckpoint", this.updateCurrentRoom);
try {
const stats = await eventIndex.getStats();
if (stats) {
eventIndexSize = stats.size;
eventCount = stats.eventCount;
}
} catch {
// This call may fail if sporadically, not a huge issue as we
// will try later again in the updateCurrentRoom call and
// probably succeed.
}
const roomStats = eventIndex.crawlingRooms();
crawlingRoomsCount = roomStats.crawlingRooms.size;
roomCount = roomStats.totalRooms.size;
const room = eventIndex.currentRoom();
if (room) currentRoom = room.name;
await this.updateCurrentRoom(room);
}
this.setState({
eventIndexSize,
eventCount,
crawlingRoomsCount,
roomCount,
currentRoom,
});
}
private onDisable = async (): Promise<void> => {
@@ -149,7 +135,7 @@ export default class ManageEventIndexDialog extends React.Component<IProps, ISta
crawlerState = _t("settings|security|message_search_indexing", { currentRoom: this.state.currentRoom });
}
const doneRooms = Math.max(0, this.state.roomCount - this.state.crawlingRoomsCount);
const doneRooms = Math.max(0, this.state.eventIndexRoomCount - this.state.crawlingRoomsCount);
const eventIndexingSettings = (
<div>
@@ -169,6 +155,10 @@ export default class ManageEventIndexDialog extends React.Component<IProps, ISta
totalRooms: formatCountLong(this.state.roomCount),
})}{" "}
<br />
{_t("settings|security|message_search_pending_rooms", {
pendingRooms: formatCountLong(this.state.crawlingRoomsCount),
})}
<br />
<Field
label={_t("settings|security|message_search_sleep_time")}
type="number"
+1
View File
@@ -2964,6 +2964,7 @@
"message_search_indexing": "Currently indexing: %(currentRoom)s",
"message_search_indexing_idle": "Not currently indexing messages for any room.",
"message_search_intro": "%(brand)s is securely caching encrypted messages locally for them to appear in search results:",
"message_search_pending_rooms": "Rooms awaiting indexing: %(pendingRooms)s",
"message_search_room_progress": "%(doneRooms)s out of %(totalRooms)s",
"message_search_section": "Message search",
"message_search_sleep_time": "How fast should messages be downloaded.",