mirror of
https://github.com/element-hq/element-web
synced 2024-11-24 18:25:49 +03:00
EventIndex: Use a setting for the crawler sleep time.
This commit is contained in:
parent
b7b66cfd9a
commit
47156351a6
2 changed files with 25 additions and 4 deletions
|
@ -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
|
||||
|
|
|
@ -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,
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue