@quenty/datastore 7.23.1-canary.402.40f9a1f.0 → 7.23.1-canary.402.a911cda.0

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/CHANGELOG.md CHANGED
@@ -3,11 +3,12 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
- ## [7.23.1-canary.402.40f9a1f.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/datastore@7.23.0...@quenty/datastore@7.23.1-canary.402.40f9a1f.0) (2023-08-16)
6
+ ## [7.23.1-canary.402.a911cda.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/datastore@7.23.0...@quenty/datastore@7.23.1-canary.402.a911cda.0) (2023-08-23)
7
7
 
8
8
 
9
9
  ### Bug Fixes
10
10
 
11
+ * Changed events weren't firing for the datastore stage ([04f2cf9](https://github.com/Quenty/NevermoreEngine/commit/04f2cf921fcc5e5c7db8ed16b8c76a0bc06c5688))
11
12
  * Fix additional components but data store writing ping-pings back and forth ([667015d](https://github.com/Quenty/NevermoreEngine/commit/667015d65fe44856076346394c4b218bead012b5))
12
13
  * More data store improvements ([b4c5918](https://github.com/Quenty/NevermoreEngine/commit/b4c5918055ffde9e3c5041e98432a13f4e8c913a))
13
14
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@quenty/datastore",
3
- "version": "7.23.1-canary.402.40f9a1f.0",
3
+ "version": "7.23.1-canary.402.a911cda.0",
4
4
  "description": "Quenty's Datastore implementation for Roblox",
5
5
  "keywords": [
6
6
  "Roblox",
@@ -26,21 +26,21 @@
26
26
  "Quenty"
27
27
  ],
28
28
  "dependencies": {
29
- "@quenty/baseobject": "6.2.2-canary.402.40f9a1f.0",
30
- "@quenty/bindtocloseservice": "2.18.1-canary.402.40f9a1f.0",
31
- "@quenty/loader": "6.2.2-canary.402.40f9a1f.0",
32
- "@quenty/maid": "2.5.0",
33
- "@quenty/math": "2.4.1-canary.402.40f9a1f.0",
34
- "@quenty/promise": "6.7.1-canary.402.40f9a1f.0",
35
- "@quenty/rx": "7.14.1-canary.402.40f9a1f.0",
36
- "@quenty/servicebag": "6.8.1-canary.402.40f9a1f.0",
29
+ "@quenty/baseobject": "6.2.2-canary.402.a911cda.0",
30
+ "@quenty/bindtocloseservice": "2.18.1-canary.402.a911cda.0",
31
+ "@quenty/loader": "6.2.2-canary.402.a911cda.0",
32
+ "@quenty/maid": "2.5.1-canary.402.a911cda.0",
33
+ "@quenty/math": "2.4.1-canary.402.a911cda.0",
34
+ "@quenty/promise": "6.7.1-canary.402.a911cda.0",
35
+ "@quenty/rx": "7.14.1-canary.402.a911cda.0",
36
+ "@quenty/servicebag": "6.8.1-canary.402.a911cda.0",
37
37
  "@quenty/signal": "2.4.0",
38
38
  "@quenty/symbol": "2.2.0",
39
- "@quenty/table": "3.2.1-canary.402.40f9a1f.0",
40
- "@quenty/valueobject": "7.21.1-canary.402.40f9a1f.0"
39
+ "@quenty/table": "3.2.1-canary.402.a911cda.0",
40
+ "@quenty/valueobject": "7.21.1-canary.402.a911cda.0"
41
41
  },
42
42
  "publishConfig": {
43
43
  "access": "public"
44
44
  },
45
- "gitHead": "40f9a1fad543e137f1e639cafc45a98cb439b0b6"
45
+ "gitHead": "a911cdaf4f1039b599528cec17b027f4660e4fd8"
46
46
  }
@@ -363,7 +363,7 @@ function DataStore:_doDataSync(writer, doMergeNewData)
363
363
  end))
364
364
  else
365
365
  if self._debugWriting then
366
- print(string.format("[DataStore] - DataStorePromises.updateAsync(%q)", self._key))
366
+ print(string.format("[DataStore] - DataStorePromises.updateAsync(%q) with doMergeNewData = %s", self._key, tostring(doMergeNewData)))
367
367
  end
368
368
 
369
369
  promise:Resolve(maid:GivePromise(DataStorePromises.updateAsync(self._robloxDataStore, self._key, function(original, datastoreKeyInfo)
@@ -29,6 +29,8 @@ local Set = require("Set")
29
29
  local Table = require("Table")
30
30
  local DataStoreSnapshotUtils = require("DataStoreSnapshotUtils")
31
31
 
32
+ local SLOW_INTEGRITY_CHECK_ENABLED = true
33
+
32
34
  local DataStoreStage = setmetatable({}, BaseObject)
33
35
  DataStoreStage.ClassName = "DataStoreStage"
34
36
  DataStoreStage.__index = DataStoreStage
@@ -373,7 +375,9 @@ end
373
375
  ]=]
374
376
  function DataStoreStage:MergeDiffSnapshot(diffSnapshot)
375
377
  self:_checkIntegrity()
378
+
376
379
  self._baseDataSnapshot = self:_updateStoresAndComputeBaseDataSnapshotFromDiffSnapshot(diffSnapshot)
380
+
377
381
  self:_updateViewSnapshot()
378
382
  self:_checkIntegrity()
379
383
  end
@@ -414,7 +418,8 @@ function DataStoreStage:MarkDataAsSaved(parentWriter)
414
418
  end
415
419
 
416
420
  for key, value in pairs(dataToSave) do
417
- if self._saveDataSnapshot[key] == value then
421
+ local ourSnapshotValue = self._saveDataSnapshot[key]
422
+ if Table.deepEquivalent(ourSnapshotValue, value) or ourSnapshotValue == nil then
418
423
  -- This shouldn't fire any event because our save data is matching
419
424
  newBaseDataSnapshot[key] = self:_updateStoresAndComputeBaseDataSnapshotValueFromDiffSnapshot(key, value)
420
425
  newSaveSnapshot[key] = nil
@@ -704,6 +709,8 @@ function DataStoreStage:_updateStoresAndComputeBaseDataSnapshotFromDiffSnapshot(
704
709
  end
705
710
 
706
711
  return table.freeze(newBaseDataSnapshot)
712
+ elseif diffSnapshot == nil then
713
+ return self._baseDataSnapshot
707
714
  else
708
715
  return diffSnapshot
709
716
  end
@@ -747,50 +754,52 @@ function DataStoreStage:_updateViewSnapshot()
747
754
 
748
755
  local newViewSnapshot = self:_computeNewViewSnapshot()
749
756
 
750
- -- This will only filter out a few items
751
- if self._viewSnapshot == newViewSnapshot then
752
- return
757
+ if not Table.deepEquivalent(self._viewSnapshot, newViewSnapshot) then
758
+ local previousViewSnapshot = self._viewSnapshot
759
+ self._viewSnapshot = newViewSnapshot
760
+
761
+ -- Fire off changed keys
762
+ local changedKeys = self:_computeChangedKeys(previousViewSnapshot, newViewSnapshot)
763
+ if next(changedKeys) ~= nil then
764
+ if type(newViewSnapshot) == "table" then
765
+ for key, _ in pairs(changedKeys) do
766
+ self._keySubscriptions:Fire(key, newViewSnapshot[key])
767
+ end
768
+ else
769
+ for key, _ in pairs(changedKeys) do
770
+ self._keySubscriptions:Fire(key, nil)
771
+ end
772
+ end
773
+ end
774
+
775
+ self.Changed:Fire(self._viewSnapshot)
753
776
  end
754
777
 
755
- local previousView = self._viewSnapshot
778
+ self:_checkIntegrity()
779
+ end
756
780
 
781
+ function DataStoreStage:_computeChangedKeys(previousViewSnapshot, newViewSnapshot)
757
782
  -- Detect keys that changed
758
- local changedKeys
759
- if type(previousView) == "table" and type(newViewSnapshot) == "table" then
760
- changedKeys = {}
761
- local keys = Set.union(Set.fromKeys(previousView), Set.fromKeys(newViewSnapshot))
783
+ if type(previousViewSnapshot) == "table" and type(newViewSnapshot) == "table" then
784
+ local changedKeys = {}
785
+
786
+ local keys = Set.union(Set.fromKeys(previousViewSnapshot), Set.fromKeys(newViewSnapshot))
762
787
  for key, _ in pairs(keys) do
763
- if previousView[key] ~= newViewSnapshot[key] then
788
+ if not Table.deepEquivalent(previousViewSnapshot[key], newViewSnapshot[key]) then
764
789
  changedKeys[key] = true
765
790
  end
766
791
  end
792
+
793
+ return changedKeys
767
794
  elseif type(newViewSnapshot) == "table" then
768
795
  -- Swap to table, all keys change
769
- changedKeys = Set.fromKeys(newViewSnapshot)
770
- elseif type(previousView) == "table" then
796
+ return Set.fromKeys(newViewSnapshot)
797
+ elseif type(previousViewSnapshot) == "table" then
771
798
  -- Swap from table, all keys change
772
- changedKeys = Set.fromKeys(previousView)
799
+ return Set.fromKeys(previousViewSnapshot)
773
800
  else
774
- changedKeys = {}
801
+ return {}
775
802
  end
776
-
777
- if next(changedKeys) ~= nil then
778
- self._viewSnapshot = newViewSnapshot
779
-
780
- if type(newViewSnapshot) == "table" then
781
- for key, value in pairs(changedKeys) do
782
- self._keySubscriptions:Fire(key, newViewSnapshot[value])
783
- end
784
- else
785
- for key, _ in pairs(changedKeys) do
786
- self._keySubscriptions:Fire(key, nil)
787
- end
788
- end
789
-
790
- self.Changed:Fire(self._viewSnapshot)
791
- end
792
-
793
- self:_checkIntegrity()
794
803
  end
795
804
 
796
805
  function DataStoreStage:_updateViewSnapshotAtKey(key)
@@ -856,6 +865,9 @@ function DataStoreStage:_computeNewViewSnapshot()
856
865
 
857
866
  return table.freeze(newView)
858
867
  else
868
+ assert(self._saveDataSnapshot ~= nil, "Bad _saveDataSnapshot")
869
+ assert(type(self._saveDataSnapshot) ~= "table", "Bad self._saveDataSnapshot")
870
+
859
871
  -- If save data isn't nil or a table then we are to return the save table
860
872
  return self._saveDataSnapshot
861
873
  end
@@ -942,6 +954,10 @@ function DataStoreStage:_storeAtKey(key, value)
942
954
  end
943
955
 
944
956
  function DataStoreStage:_checkIntegrity()
957
+ if not SLOW_INTEGRITY_CHECK_ENABLED then
958
+ return
959
+ end
960
+
945
961
  assert(self._baseDataSnapshot ~= DataStoreDeleteToken, "BaseDataSnapshot should not be DataStoreDeleteToken")
946
962
  assert(self._viewSnapshot ~= DataStoreDeleteToken, "ViewSnapshot should not be DataStoreDeleteToken")
947
963