mirror of https://github.com/vector-im/riot-web
EventIndex: Use a setting for the crawler sleep time.
parent
b7b66cfd9a
commit
47156351a6
|
@ -16,6 +16,8 @@ limitations under the License.
|
||||||
|
|
||||||
import PlatformPeg from "../PlatformPeg";
|
import PlatformPeg from "../PlatformPeg";
|
||||||
import {MatrixClientPeg} from "../MatrixClientPeg";
|
import {MatrixClientPeg} from "../MatrixClientPeg";
|
||||||
|
import SettingsStore from '../settings/SettingsStore';
|
||||||
|
import {SettingLevel} from "../settings/SettingsStore";
|
||||||
import {sleep} from "../utils/promise";
|
import {sleep} from "../utils/promise";
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -24,9 +26,9 @@ import {sleep} from "../utils/promise";
|
||||||
export default class EventIndex {
|
export default class EventIndex {
|
||||||
constructor() {
|
constructor() {
|
||||||
this.crawlerCheckpoints = [];
|
this.crawlerCheckpoints = [];
|
||||||
// The time that the crawler will wait between /rooms/{room_id}/messages
|
// The time in ms that the crawler will wait loop iterations if there
|
||||||
// requests
|
// have not been any checkpoints to consume in the last iteration.
|
||||||
this._crawlerTimeout = 3000;
|
this._crawlerIdleTime = 5000;
|
||||||
// The maximum number of events our crawler should fetch in a single
|
// The maximum number of events our crawler should fetch in a single
|
||||||
// crawl.
|
// crawl.
|
||||||
this._eventsPerCrawl = 100;
|
this._eventsPerCrawl = 100;
|
||||||
|
@ -194,11 +196,22 @@ export default class EventIndex {
|
||||||
cancelled = true;
|
cancelled = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let idle = false;
|
||||||
|
|
||||||
while (!cancelled) {
|
while (!cancelled) {
|
||||||
// This is a low priority task and we don't want to spam our
|
// This is a low priority task and we don't want to spam our
|
||||||
// homeserver with /messages requests so we set a hefty timeout
|
// homeserver with /messages requests so we set a hefty timeout
|
||||||
// here.
|
// 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.");
|
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
|
/// There is no checkpoint available currently, one may appear if
|
||||||
// a sync with limited room timelines happens, so go back to sleep.
|
// a sync with limited room timelines happens, so go back to sleep.
|
||||||
if (checkpoint === undefined) {
|
if (checkpoint === undefined) {
|
||||||
|
idle = true;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
idle = false;
|
||||||
|
|
||||||
console.log("EventIndex: crawling using checkpoint", checkpoint);
|
console.log("EventIndex: crawling using checkpoint", checkpoint);
|
||||||
|
|
||||||
// We have a checkpoint, let us fetch some messages, again, very
|
// We have a checkpoint, let us fetch some messages, again, very
|
||||||
|
|
|
@ -486,4 +486,9 @@ export const SETTINGS = {
|
||||||
supportedLevels: LEVELS_DEVICE_ONLY_SETTINGS,
|
supportedLevels: LEVELS_DEVICE_ONLY_SETTINGS,
|
||||||
default: RIGHT_PANEL_PHASES.GroupMemberList,
|
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 New Issue