EventIndexing: Rework the index initialization and deletion.

pull/21833/head
Damir Jelić 2019-11-14 16:13:22 +01:00
parent 448c9a8290
commit 7516f2724a
4 changed files with 63 additions and 31 deletions

View File

@ -206,6 +206,16 @@ export default class BaseEventIndexManager {
throw new Error("Unimplemented"); throw new Error("Unimplemented");
} }
/**
* close our event index.
*
* @return {Promise} A promise that will resolve once the event index has
* been closed.
*/
async closeEventIndex(): Promise<> {
throw new Error("Unimplemented");
}
/** /**
* Delete our current event index. * Delete our current event index.
* *

View File

@ -31,15 +31,6 @@ class EventIndexPeg {
this.index = null; this.index = null;
} }
/**
* Get the current event index.
*
* @return {EventIndex} The current event index.
*/
get() {
return this.index;
}
/** Create a new EventIndex and initialize it if the platform supports it. /** Create a new EventIndex and initialize it if the platform supports it.
* *
* @return {Promise<bool>} A promise that will resolve to true if an * @return {Promise<bool>} A promise that will resolve to true if an
@ -72,11 +63,30 @@ class EventIndexPeg {
} }
/** /**
* Stop our event indexer. * Get the current event index.
*
* @return {EventIndex} The current event index.
*/ */
get() {
return this.index;
}
stop() { stop() {
if (this.index === null) return; if (this.index === null) return;
this.index.stop(); this.index.stopCrawler();
}
/**
* Unset our event store
*
* After a call to this the init() method will need to be called again.
*
* @return {Promise} A promise that will resolve once the event index is
* closed.
*/
async unset() {
if (this.index === null) return;
this.index.close();
this.index = null; this.index = null;
} }
@ -89,11 +99,16 @@ class EventIndexPeg {
* deleted. * deleted.
*/ */
async deleteEventIndex() { async deleteEventIndex() {
if (this.index === null) return; const indexManager = PlatformPeg.get().getEventIndexingManager();
this.index.deleteEventIndex();
if (indexManager !== null) {
this.stop();
console.log("EventIndex: Deleting event index.");
await indexManager.deleteEventIndex();
this.index = null; this.index = null;
} }
} }
}
if (!global.mxEventIndexPeg) { if (!global.mxEventIndexPeg) {
global.mxEventIndexPeg = new EventIndexPeg(); global.mxEventIndexPeg = new EventIndexPeg();

View File

@ -35,9 +35,7 @@ export default class EventIndexer {
async init() { async init() {
const indexManager = PlatformPeg.get().getEventIndexingManager(); const indexManager = PlatformPeg.get().getEventIndexingManager();
if (indexManager === null) return false; return indexManager.initEventIndex();
indexManager.initEventIndex();
return true;
} }
async onSync(state, prevState, data) { async onSync(state, prevState, data) {
@ -198,7 +196,6 @@ export default class EventIndexer {
console.log("EventIndex: Running the crawler loop."); console.log("EventIndex: Running the crawler loop.");
if (cancelled) { if (cancelled) {
console.log("EventIndex: Cancelling the crawler.");
break; break;
} }
@ -373,26 +370,35 @@ export default class EventIndexer {
this.crawlerCheckpoints.push(backwardsCheckpoint); this.crawlerCheckpoints.push(backwardsCheckpoint);
} }
startCrawler() {
if (this._crawlerRef !== null) return;
const crawlerHandle = {};
this.crawlerFunc(crawlerHandle);
this._crawlerRef = crawlerHandle;
}
stopCrawler() {
if (this._crawlerRef === null) return;
this._crawlerRef.cancel();
this._crawlerRef = null;
}
async close() {
const indexManager = PlatformPeg.get().getEventIndexingManager();
this.stopCrawler();
return indexManager.closeEventIndex();
}
async deleteEventIndex() { async deleteEventIndex() {
const indexManager = PlatformPeg.get().getEventIndexingManager(); const indexManager = PlatformPeg.get().getEventIndexingManager();
if (indexManager !== null) { if (indexManager !== null) {
console.log("EventIndex: Deleting event index."); this.stopCrawler();
this.crawlerRef.cancel();
await indexManager.deleteEventIndex(); await indexManager.deleteEventIndex();
} }
} }
startCrawler() {
const crawlerHandle = {};
this.crawlerFunc(crawlerHandle);
this.crawlerRef = crawlerHandle;
}
stop() {
this._crawlerRef.cancel();
this._crawlerRef = null;
}
async search(searchArgs) { async search(searchArgs) {
const indexManager = PlatformPeg.get().getEventIndexingManager(); const indexManager = PlatformPeg.get().getEventIndexingManager();
return indexManager.searchEventIndex(searchArgs); return indexManager.searchEventIndex(searchArgs);

View File

@ -662,6 +662,7 @@ export function stopMatrixClient(unsetClient=true) {
if (unsetClient) { if (unsetClient) {
MatrixClientPeg.unset(); MatrixClientPeg.unset();
EventIndexPeg.unset().done();
} }
} }
} }