mirror of
https://github.com/vector-im/element-web.git
synced 2024-11-17 14:05:04 +08:00
EventIndexPanel: Dynamically update the indexer stats.
This commit is contained in:
parent
1b9b30d4ea
commit
8de149704e
@ -45,6 +45,29 @@ export default class EventIndexPanel extends React.Component {
|
||||
};
|
||||
}
|
||||
|
||||
async updateCurrentRoom(room) {
|
||||
const eventIndex = EventIndexPeg.get();
|
||||
const stats = await eventIndex.getStats();
|
||||
let currentRoom = null;
|
||||
|
||||
if (room) currentRoom = room.name;
|
||||
|
||||
this.setState({
|
||||
eventIndexSize: stats.size,
|
||||
roomCount: stats.roomCount,
|
||||
eventCount: stats.eventCount,
|
||||
currentRoom: currentRoom,
|
||||
});
|
||||
}
|
||||
|
||||
componentWillUnmount(): void {
|
||||
const eventIndex = EventIndexPeg.get();
|
||||
|
||||
if (eventIndex !== null) {
|
||||
eventIndex.removeListener("changedCheckpoint", this.updateCurrentRoom.bind(this));
|
||||
}
|
||||
}
|
||||
|
||||
async componentWillMount(): void {
|
||||
let eventIndexSize = 0;
|
||||
let roomCount = 0;
|
||||
@ -56,6 +79,8 @@ export default class EventIndexPanel extends React.Component {
|
||||
const eventIndex = EventIndexPeg.get();
|
||||
|
||||
if (eventIndex !== null) {
|
||||
eventIndex.on("changedCheckpoint", this.updateCurrentRoom.bind(this));
|
||||
|
||||
const stats = await eventIndex.getStats();
|
||||
eventIndexSize = stats.size;
|
||||
roomCount = stats.roomCount;
|
||||
|
@ -19,6 +19,7 @@ import {MatrixClientPeg} from "../MatrixClientPeg";
|
||||
import SettingsStore from '../settings/SettingsStore';
|
||||
import {SettingLevel} from "../settings/SettingsStore";
|
||||
import {sleep} from "../utils/promise";
|
||||
import {EventEmitter} from "events";
|
||||
|
||||
/*
|
||||
* Event indexing class that wraps the platform specific event indexing.
|
||||
@ -35,6 +36,7 @@ export default class EventIndex {
|
||||
this._crawler = null;
|
||||
this._currentCheckpoint = null;
|
||||
this.liveEventsForIndex = new Set();
|
||||
this._eventEmitter = new EventEmitter();
|
||||
}
|
||||
|
||||
async init() {
|
||||
@ -185,6 +187,10 @@ export default class EventIndex {
|
||||
indexManager.addEventToIndex(e, profile);
|
||||
}
|
||||
|
||||
emitNewCheckpoint() {
|
||||
this._eventEmitter.emit("changedCheckpoint", this.currentRoom());
|
||||
}
|
||||
|
||||
async crawlerFunc() {
|
||||
let cancelled = false;
|
||||
|
||||
@ -214,7 +220,10 @@ export default class EventIndex {
|
||||
sleepTime = this._crawlerIdleTime;
|
||||
}
|
||||
|
||||
this._currentCheckpoint = null;
|
||||
if (this._currentCheckpoint !== null) {
|
||||
this._currentCheckpoint = null;
|
||||
this.emitNewCheckpoint();
|
||||
}
|
||||
|
||||
await sleep(sleepTime);
|
||||
|
||||
@ -234,6 +243,7 @@ export default class EventIndex {
|
||||
}
|
||||
|
||||
this._currentCheckpoint = checkpoint;
|
||||
this.emitNewCheckpoint();
|
||||
|
||||
idle = false;
|
||||
|
||||
@ -465,18 +475,23 @@ export default class EventIndex {
|
||||
*/
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
on(eventName, callback) {
|
||||
this._eventEmitter.on(eventName, callback);
|
||||
}
|
||||
|
||||
removeListener(eventName, callback) {
|
||||
this._eventEmitter.removeListener(eventName, callback);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user