EventIndex: Use a setting for the crawler sleep time.

This commit is contained in:
Damir Jelić 2019-11-26 13:25:34 +01:00
parent b7b66cfd9a
commit 47156351a6
2 changed files with 25 additions and 4 deletions

View file

@ -16,6 +16,8 @@ limitations under the License.
import PlatformPeg from "../PlatformPeg";
import {MatrixClientPeg} from "../MatrixClientPeg";
import SettingsStore from '../settings/SettingsStore';
import {SettingLevel} from "../settings/SettingsStore";
import {sleep} from "../utils/promise";
/*
@ -24,9 +26,9 @@ import {sleep} from "../utils/promise";
export default class EventIndex {
constructor() {
this.crawlerCheckpoints = [];
// The time that the crawler will wait between /rooms/{room_id}/messages
// requests
this._crawlerTimeout = 3000;
// The time in ms that the crawler will wait loop iterations if there
// have not been any checkpoints to consume in the last iteration.
this._crawlerIdleTime = 5000;
// The maximum number of events our crawler should fetch in a single
// crawl.
this._eventsPerCrawl = 100;
@ -194,11 +196,22 @@ export default class EventIndex {
cancelled = true;
};
let idle = false;
while (!cancelled) {
// This is a low priority task and we don't want to spam our
// homeserver with /messages requests so we set a hefty timeout
// here.
await sleep(this._crawlerTimeout);
let sleepTime = SettingsStore.getValueAt(SettingLevel.DEVICE, 'crawlerSleepTime');
// Don't let the user configure a lower sleep time than 100 ms.
sleepTime = Math.max(sleepTime, 100);
if (idle) {
sleepTime = this._crawlerIdleTime;
}
await sleep(sleepTime);
console.log("EventIndex: Running the crawler loop.");
@ -211,9 +224,12 @@ export default class EventIndex {
/// There is no checkpoint available currently, one may appear if
// a sync with limited room timelines happens, so go back to sleep.
if (checkpoint === undefined) {
idle = true;
continue;
}
idle = false;
console.log("EventIndex: crawling using checkpoint", checkpoint);
// We have a checkpoint, let us fetch some messages, again, very

View file

@ -486,4 +486,9 @@ export const SETTINGS = {
supportedLevels: LEVELS_DEVICE_ONLY_SETTINGS,
default: RIGHT_PANEL_PHASES.GroupMemberList,
},
"crawlerSleepTime": {
supportedLevels: LEVELS_DEVICE_ONLY_SETTINGS,
displayName: _td("How long should the crawler wait between requests"),
default: 3000,
}
};