From f479f6043f7423fbaba2e5697c6bc73ef40bcb05 Mon Sep 17 00:00:00 2001 From: Michael Mainguy Date: Fri, 26 Apr 2024 07:05:46 -0500 Subject: [PATCH] Added Metadata sync for friendly name --- src/integration/pouchdbPersistenceManager.ts | 24 +++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/src/integration/pouchdbPersistenceManager.ts b/src/integration/pouchdbPersistenceManager.ts index a202740..c123f8d 100644 --- a/src/integration/pouchdbPersistenceManager.ts +++ b/src/integration/pouchdbPersistenceManager.ts @@ -94,6 +94,26 @@ export class PouchdbPersistenceManager { await this.sendLocalDataToScene(); } + private async setupMetadata(current: string) { + try { + const doc = await this.db.get('metadata'); + if (doc && doc.friendly) { + localStorage.setItem(current, doc.friendly); + } + } catch (err) { + if (err.status == 404) { + console.log('no metadata found'); + const friendly = localStorage.getItem(current); + if (friendly) { + console.log('local friendly name found ', friendly, ' setting metadata'); + const newDoc = {_id: 'metadata', friendly: friendly}; + await this.db.put(newDoc); + } else { + console.log('no friendly name found'); + } + } + } + } private async initLocal(): Promise { try { let sync = false; @@ -103,8 +123,10 @@ export class PouchdbPersistenceManager { } else { current = 'localdb'; } - this.db = new PouchDB(current); + this.db = new PouchDB(current, {auto_compaction: true}); + await this.db.compact(); if (sync) { + await this.setupMetadata(current); await this.beginSync(current); } return true;