mirror of
https://github.com/vector-im/element-web.git
synced 2025-08-28 18:01:46 +02:00
EventIndex: Rework the crawler cancellation.
This commit is contained in:
parent
8d7e7d0cc4
commit
4a6623bc00
@ -29,7 +29,7 @@ export default class EventIndex {
|
|||||||
// 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;
|
||||||
this._crawlerRef = null;
|
this._crawler = null;
|
||||||
this.liveEventsForIndex = new Set();
|
this.liveEventsForIndex = new Set();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -165,7 +165,7 @@ export default class EventIndex {
|
|||||||
indexManager.addEventToIndex(e, profile);
|
indexManager.addEventToIndex(e, profile);
|
||||||
}
|
}
|
||||||
|
|
||||||
async crawlerFunc(handle) {
|
async crawlerFunc() {
|
||||||
// TODO either put this in a better place or find a library provided
|
// TODO either put this in a better place or find a library provided
|
||||||
// method that does this.
|
// method that does this.
|
||||||
const sleep = async (ms) => {
|
const sleep = async (ms) => {
|
||||||
@ -179,7 +179,9 @@ export default class EventIndex {
|
|||||||
const client = MatrixClientPeg.get();
|
const client = MatrixClientPeg.get();
|
||||||
const indexManager = PlatformPeg.get().getEventIndexingManager();
|
const indexManager = PlatformPeg.get().getEventIndexingManager();
|
||||||
|
|
||||||
handle.cancel = () => {
|
this._crawler = {};
|
||||||
|
|
||||||
|
this._crawler.cancel = () => {
|
||||||
cancelled = true;
|
cancelled = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -340,6 +342,8 @@ export default class EventIndex {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this._crawler = null;
|
||||||
|
|
||||||
console.log("EventIndex: Stopping crawler function");
|
console.log("EventIndex: Stopping crawler function");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -366,18 +370,13 @@ export default class EventIndex {
|
|||||||
}
|
}
|
||||||
|
|
||||||
startCrawler() {
|
startCrawler() {
|
||||||
if (this._crawlerRef !== null) return;
|
if (this._crawler !== null) return;
|
||||||
|
this.crawlerFunc();
|
||||||
const crawlerHandle = {};
|
|
||||||
this.crawlerFunc(crawlerHandle);
|
|
||||||
this._crawlerRef = crawlerHandle;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
stopCrawler() {
|
stopCrawler() {
|
||||||
if (this._crawlerRef === null) return;
|
if (this._crawler === null) return;
|
||||||
|
this._crawler.cancel();
|
||||||
this._crawlerRef.cancel();
|
|
||||||
this._crawlerRef = null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async close() {
|
async close() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user