mirror of https://github.com/vector-im/riot-web
EventIndexPanel: Dynamically update the indexer stats.
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 {
|
async componentWillMount(): void {
|
||||||
let eventIndexSize = 0;
|
let eventIndexSize = 0;
|
||||||
let roomCount = 0;
|
let roomCount = 0;
|
||||||
|
@ -56,6 +79,8 @@ export default class EventIndexPanel extends React.Component {
|
||||||
const eventIndex = EventIndexPeg.get();
|
const eventIndex = EventIndexPeg.get();
|
||||||
|
|
||||||
if (eventIndex !== null) {
|
if (eventIndex !== null) {
|
||||||
|
eventIndex.on("changedCheckpoint", this.updateCurrentRoom.bind(this));
|
||||||
|
|
||||||
const stats = await eventIndex.getStats();
|
const stats = await eventIndex.getStats();
|
||||||
eventIndexSize = stats.size;
|
eventIndexSize = stats.size;
|
||||||
roomCount = stats.roomCount;
|
roomCount = stats.roomCount;
|
||||||
|
|
|
@ -19,6 +19,7 @@ import {MatrixClientPeg} from "../MatrixClientPeg";
|
||||||
import SettingsStore from '../settings/SettingsStore';
|
import SettingsStore from '../settings/SettingsStore';
|
||||||
import {SettingLevel} from "../settings/SettingsStore";
|
import {SettingLevel} from "../settings/SettingsStore";
|
||||||
import {sleep} from "../utils/promise";
|
import {sleep} from "../utils/promise";
|
||||||
|
import {EventEmitter} from "events";
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Event indexing class that wraps the platform specific event indexing.
|
* Event indexing class that wraps the platform specific event indexing.
|
||||||
|
@ -35,6 +36,7 @@ export default class EventIndex {
|
||||||
this._crawler = null;
|
this._crawler = null;
|
||||||
this._currentCheckpoint = null;
|
this._currentCheckpoint = null;
|
||||||
this.liveEventsForIndex = new Set();
|
this.liveEventsForIndex = new Set();
|
||||||
|
this._eventEmitter = new EventEmitter();
|
||||||
}
|
}
|
||||||
|
|
||||||
async init() {
|
async init() {
|
||||||
|
@ -185,6 +187,10 @@ export default class EventIndex {
|
||||||
indexManager.addEventToIndex(e, profile);
|
indexManager.addEventToIndex(e, profile);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
emitNewCheckpoint() {
|
||||||
|
this._eventEmitter.emit("changedCheckpoint", this.currentRoom());
|
||||||
|
}
|
||||||
|
|
||||||
async crawlerFunc() {
|
async crawlerFunc() {
|
||||||
let cancelled = false;
|
let cancelled = false;
|
||||||
|
|
||||||
|
@ -214,7 +220,10 @@ export default class EventIndex {
|
||||||
sleepTime = this._crawlerIdleTime;
|
sleepTime = this._crawlerIdleTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
this._currentCheckpoint = null;
|
if (this._currentCheckpoint !== null) {
|
||||||
|
this._currentCheckpoint = null;
|
||||||
|
this.emitNewCheckpoint();
|
||||||
|
}
|
||||||
|
|
||||||
await sleep(sleepTime);
|
await sleep(sleepTime);
|
||||||
|
|
||||||
|
@ -234,6 +243,7 @@ export default class EventIndex {
|
||||||
}
|
}
|
||||||
|
|
||||||
this._currentCheckpoint = checkpoint;
|
this._currentCheckpoint = checkpoint;
|
||||||
|
this.emitNewCheckpoint();
|
||||||
|
|
||||||
idle = false;
|
idle = false;
|
||||||
|
|
||||||
|
@ -465,18 +475,23 @@ export default class EventIndex {
|
||||||
*/
|
*/
|
||||||
currentRoom() {
|
currentRoom() {
|
||||||
if (this._currentCheckpoint === null && this.crawlerCheckpoints.length === 0) {
|
if (this._currentCheckpoint === null && this.crawlerCheckpoints.length === 0) {
|
||||||
console.log("EventIndex: No current nor any checkpoint");
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
const client = MatrixClientPeg.get();
|
const client = MatrixClientPeg.get();
|
||||||
|
|
||||||
if (this._currentCheckpoint !== null) {
|
if (this._currentCheckpoint !== null) {
|
||||||
console.log("EventIndex: Current checkpoint available");
|
|
||||||
return client.getRoom(this._currentCheckpoint.roomId);
|
return client.getRoom(this._currentCheckpoint.roomId);
|
||||||
} else {
|
} else {
|
||||||
console.log("EventIndex: No current but have checkpoint available");
|
|
||||||
return client.getRoom(this.crawlerCheckpoints[0].roomId);
|
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