fix: init trash & monographs after notes

This commit is contained in:
thecodrr
2021-12-15 15:21:32 +05:00
parent 7cc5421ad2
commit cadf77e09d
3 changed files with 13 additions and 2 deletions

View File

@@ -70,6 +70,15 @@ class Database {
this.syncer.stopAutoSync(); this.syncer.stopAutoSync();
this.disconnectSSE(); this.disconnectSSE();
}); });
EV.subscribe(EVENTS.databaseCollectionInitiated, async (collectionName) => {
switch (collectionName) {
case "notes": {
await this.monographs.init();
await this.trash.init();
break;
}
}
});
this.session = new Session(this.storage); this.session = new Session(this.storage);
await this._validate(); await this._validate();
@@ -103,7 +112,6 @@ class Database {
this.trash = new Trash(this); this.trash = new Trash(this);
await this.trash.cleanup();
await this.settings.init(); await this.settings.init();
await this.outbox.init(); await this.outbox.init();
await this.user.init(); await this.user.init();

View File

@@ -6,7 +6,7 @@ class Collection {
static async new(db, name, cached = true, deferred = false) { static async new(db, name, cached = true, deferred = false) {
const collection = new this(db, name, cached); const collection = new this(db, name, cached);
if (!deferred && collection.init) await collection.init(); if (!deferred) await collection.init();
else await collection._collection.indexer.init(); else await collection._collection.indexer.init();
if (collection._collection.clear) if (collection._collection.clear)
@@ -21,6 +21,7 @@ class Collection {
async init() { async init() {
if (this.initialized) return; if (this.initialized) return;
await this._collection.init(); await this._collection.init();
EV.publish(EVENTS.databaseCollectionInitiated, this.collectionName);
this.initialized = true; this.initialized = true;
} }
@@ -30,6 +31,7 @@ class Collection {
*/ */
constructor(db, name, cached) { constructor(db, name, cached) {
this._db = db; this._db = db;
this.collectionName = name;
if (cached) this._collection = new CachedCollection(this._db.storage, name); if (cached) this._collection = new CachedCollection(this._db.storage, name);
else this._collection = new IndexedCollection(this._db.storage, name); else this._collection = new IndexedCollection(this._db.storage, name);
} }

View File

@@ -43,6 +43,7 @@ export const EVENTS = {
databaseSyncRequested: "db:syncRequested", databaseSyncRequested: "db:syncRequested",
databaseMigrated: "db:migrated", databaseMigrated: "db:migrated",
databaseUpdated: "db:updated", databaseUpdated: "db:updated",
databaseCollectionInitiated: "db:collectionInitiated",
appRefreshRequested: "app:refreshRequested", appRefreshRequested: "app:refreshRequested",
noteRemoved: "note:removed", noteRemoved: "note:removed",
tokenRefreshed: "token:refreshed", tokenRefreshed: "token:refreshed",