EventIndexing: Rework the index initialization and deletion.
This commit is contained in:
parent
448c9a8290
commit
7516f2724a
4 changed files with 63 additions and 31 deletions
|
@ -206,6 +206,16 @@ export default class BaseEventIndexManager {
|
|||
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.
|
||||
*
|
||||
|
|
|
@ -31,15 +31,6 @@ class EventIndexPeg {
|
|||
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.
|
||||
*
|
||||
* @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() {
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -89,10 +99,15 @@ class EventIndexPeg {
|
|||
* deleted.
|
||||
*/
|
||||
async deleteEventIndex() {
|
||||
if (this.index === null) return;
|
||||
this.index.deleteEventIndex();
|
||||
const indexManager = PlatformPeg.get().getEventIndexingManager();
|
||||
|
||||
if (indexManager !== null) {
|
||||
this.stop();
|
||||
console.log("EventIndex: Deleting event index.");
|
||||
await indexManager.deleteEventIndex();
|
||||
this.index = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!global.mxEventIndexPeg) {
|
||||
|
|
|
@ -35,9 +35,7 @@ export default class EventIndexer {
|
|||
|
||||
async init() {
|
||||
const indexManager = PlatformPeg.get().getEventIndexingManager();
|
||||
if (indexManager === null) return false;
|
||||
indexManager.initEventIndex();
|
||||
return true;
|
||||
return indexManager.initEventIndex();
|
||||
}
|
||||
|
||||
async onSync(state, prevState, data) {
|
||||
|
@ -198,7 +196,6 @@ export default class EventIndexer {
|
|||
console.log("EventIndex: Running the crawler loop.");
|
||||
|
||||
if (cancelled) {
|
||||
console.log("EventIndex: Cancelling the crawler.");
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -373,26 +370,35 @@ export default class EventIndexer {
|
|||
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() {
|
||||
const indexManager = PlatformPeg.get().getEventIndexingManager();
|
||||
if (indexManager !== null) {
|
||||
console.log("EventIndex: Deleting event index.");
|
||||
this.crawlerRef.cancel();
|
||||
this.stopCrawler();
|
||||
await indexManager.deleteEventIndex();
|
||||
}
|
||||
}
|
||||
|
||||
startCrawler() {
|
||||
const crawlerHandle = {};
|
||||
this.crawlerFunc(crawlerHandle);
|
||||
this.crawlerRef = crawlerHandle;
|
||||
}
|
||||
|
||||
stop() {
|
||||
this._crawlerRef.cancel();
|
||||
this._crawlerRef = null;
|
||||
}
|
||||
|
||||
async search(searchArgs) {
|
||||
const indexManager = PlatformPeg.get().getEventIndexingManager();
|
||||
return indexManager.searchEventIndex(searchArgs);
|
||||
|
|
|
@ -662,6 +662,7 @@ export function stopMatrixClient(unsetClient=true) {
|
|||
|
||||
if (unsetClient) {
|
||||
MatrixClientPeg.unset();
|
||||
EventIndexPeg.unset().done();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue