changeset 67:163b4339804d

try addressing decreasing performance by rebuilding the graph occasionally
author drewp@bigasterisk.com
date Sun, 26 Jan 2020 22:07:19 -0800
parents 1bb65cb4c685
children f7143866fae1
files src/streamed_graph_client.ts
diffstat 1 files changed, 15 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/streamed_graph_client.ts	Mon Jan 20 03:01:22 2020 -0800
+++ b/src/streamed_graph_client.ts	Sun Jan 26 22:07:19 2020 -0800
@@ -11,6 +11,7 @@
   onStatus: (msg: string) => void;
   onGraphChanged: () => void;
   store: N3Store;
+  _deletedCount: number = 0;
   events!: EventSource;
   constructor(
     eventsUrl: string,
@@ -41,6 +42,11 @@
     //     });
   }
 
+  _vacuum() {
+    // workaround for the growing _ids map
+    this.store = new Store(this.store.getQuads(null, null, null, null));
+  }
+
   reconnectOnWake() {
     // it's not this, which fires on every mouse-in on a browser window, and doesn't seem to work for screen-turned-back-on
     //window.addEventListener('focus', function() { this.connect(eventsUrl); }.bind(this));
@@ -97,8 +103,16 @@
   async patchGraph(patchJson: string) {
     var patch = JSON.parse(patchJson).patch;
 
-    await eachJsonLdQuad(patch.deletes, this.store.removeQuad.bind(this.store));
+    await eachJsonLdQuad(patch.deletes, quad => {
+      this.store.removeQuad(quad);
+      this._deletedCount++;
+    });
     await eachJsonLdQuad(patch.adds, this.store.addQuad.bind(this.store));
+
+    if (this._deletedCount > 100) {
+      this._vacuum();
+      this._deletedCount = 0;
+    }
   }
 
   close() {