mirror of
https://github.com/vector-im/element-web.git
synced 2024-11-16 13:14:58 +08:00
Merge branch 'poljar/eventindex-user-version' into develop
This commit is contained in:
commit
e3ae05b6b9
@ -157,6 +157,29 @@ export default abstract class BaseEventIndexManager {
|
||||
throw new Error("Unimplemented");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the user version of the database.
|
||||
* @return {Promise<number>} A promise that will resolve to the user stored
|
||||
* version number.
|
||||
*/
|
||||
async getUserVersion(): Promise<number> {
|
||||
throw new Error("Unimplemented");
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the user stored version to the given version number.
|
||||
*
|
||||
* @param {number} version The new version that should be stored in the
|
||||
* database.
|
||||
*
|
||||
* @return {Promise<void>} A promise that will resolve once the new version
|
||||
* is stored.
|
||||
*/
|
||||
async setUserVersion(version: number): Promise<void> {
|
||||
throw new Error("Unimplemented");
|
||||
}
|
||||
|
||||
/**
|
||||
* Commit the previously queued up events to the index.
|
||||
*
|
||||
|
@ -42,9 +42,6 @@ export default class EventIndex extends EventEmitter {
|
||||
async init() {
|
||||
const indexManager = PlatformPeg.get().getEventIndexingManager();
|
||||
|
||||
await indexManager.initEventIndex();
|
||||
console.log("EventIndex: Successfully initialized the event index");
|
||||
|
||||
this.crawlerCheckpoints = await indexManager.loadCheckpoints();
|
||||
console.log("EventIndex: Loaded checkpoints", this.crawlerCheckpoints);
|
||||
|
||||
|
@ -23,6 +23,8 @@ import PlatformPeg from "../PlatformPeg";
|
||||
import EventIndex from "../indexing/EventIndex";
|
||||
import SettingsStore, {SettingLevel} from '../settings/SettingsStore';
|
||||
|
||||
const INDEX_VERSION = 1;
|
||||
|
||||
class EventIndexPeg {
|
||||
constructor() {
|
||||
this.index = null;
|
||||
@ -66,8 +68,25 @@ class EventIndexPeg {
|
||||
*/
|
||||
async initEventIndex() {
|
||||
const index = new EventIndex();
|
||||
const indexManager = PlatformPeg.get().getEventIndexingManager();
|
||||
|
||||
try {
|
||||
await indexManager.initEventIndex();
|
||||
|
||||
const userVersion = await indexManager.getUserVersion();
|
||||
const eventIndexIsEmpty = await indexManager.isEventIndexEmpty();
|
||||
|
||||
if (eventIndexIsEmpty) {
|
||||
await indexManager.setUserVersion(INDEX_VERSION);
|
||||
} else if (userVersion === 0 && !eventIndexIsEmpty) {
|
||||
await indexManager.closeEventIndex();
|
||||
await this.deleteEventIndex();
|
||||
|
||||
await indexManager.initEventIndex();
|
||||
await indexManager.setUserVersion(INDEX_VERSION);
|
||||
}
|
||||
|
||||
console.log("EventIndex: Successfully initialized the event index");
|
||||
await index.init();
|
||||
} catch (e) {
|
||||
console.log("EventIndex: Error initializing the event index", e);
|
||||
|
Loading…
Reference in New Issue
Block a user