topazcube 0.1.20 → 0.1.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/server.cjs CHANGED
@@ -1750,9 +1750,11 @@ var TopazCubeServer = class {
1750
1750
  documents = {};
1751
1751
  isLoading = {};
1752
1752
  _documentChanges = {};
1753
+ _documentChanged = {};
1753
1754
  _documentState = {};
1754
1755
  update = 0;
1755
1756
  lastUpdate = 0;
1757
+ _saveiv = null;
1756
1758
  _loopiv = null;
1757
1759
  _statsiv = null;
1758
1760
  _stillUpdating = false;
@@ -1896,6 +1898,7 @@ var TopazCubeServer = class {
1896
1898
  );
1897
1899
  if (!this._documentChanges[name]) {
1898
1900
  this._documentChanges[name] = [];
1901
+ this._documentChanged[name] = false;
1899
1902
  }
1900
1903
  }
1901
1904
  _createEmptyDocument(name) {
@@ -1954,6 +1957,9 @@ var TopazCubeServer = class {
1954
1957
  this._statsiv = setInterval(() => {
1955
1958
  this._doStats();
1956
1959
  }, 1e3);
1960
+ this._saveiv = setInterval(() => {
1961
+ this._saveChanges();
1962
+ }, 6e4);
1957
1963
  }
1958
1964
  _loop() {
1959
1965
  let now = Date.now();
@@ -2043,12 +2049,14 @@ var TopazCubeServer = class {
2043
2049
  let name = message.n;
2044
2050
  if (!this._documentChanges[name]) {
2045
2051
  this._documentChanges[name] = [];
2052
+ this._documentChanged[name] = false;
2046
2053
  }
2047
2054
  for (let op of message.p) {
2048
2055
  if (!this.canSync(client, name, op)) {
2049
2056
  continue;
2050
2057
  }
2051
2058
  this._documentChanges[name].push(op);
2059
+ this._documentChanged[name] = true;
2052
2060
  let dop = msgop(op);
2053
2061
  applyOperation(this.documents[name], dop);
2054
2062
  }
@@ -2344,6 +2352,7 @@ var TopazCubeServer = class {
2344
2352
  }
2345
2353
  _onDocumentChange(name, op, target, path, value) {
2346
2354
  this._documentChanges[name]?.push(opmsg(op, target, path, value));
2355
+ this._documentChanged[name] = true;
2347
2356
  }
2348
2357
  propertyChange(name, id, property) {
2349
2358
  let doc = this.documents[name];
@@ -2649,6 +2658,17 @@ var TopazCubeServer = class {
2649
2658
  await this._saveDocument(name);
2650
2659
  }
2651
2660
  }
2661
+ async _saveChanges() {
2662
+ if (!this.allowSave) {
2663
+ return;
2664
+ }
2665
+ for (let name in this._documentChanged) {
2666
+ if (this._documentChanged[name]) {
2667
+ await this._saveDocument(name);
2668
+ this._documentChanged[name] = false;
2669
+ }
2670
+ }
2671
+ }
2652
2672
  _initServerDocument() {
2653
2673
  this.documents["_server"] = {
2654
2674
  nextUID: 100
@@ -2660,6 +2680,8 @@ var TopazCubeServer = class {
2660
2680
  this.log("\nEXIT: Caught interrupt signal " + signal);
2661
2681
  this._exited = true;
2662
2682
  clearInterval(this._loopiv);
2683
+ clearInterval(this._statsiv);
2684
+ clearInterval(this._saveiv);
2663
2685
  this.onBeforeExit();
2664
2686
  this.broadcast({ server: "Going down" });
2665
2687
  this._saveAllDocuments();