envio 2.26.0-rc.0 → 2.26.0-rc.2

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.
@@ -2,6 +2,8 @@
2
2
  'use strict';
3
3
 
4
4
  var Js_exn = require("rescript/lib/js/js_exn.js");
5
+ var Logging = require("./Logging.res.js");
6
+ var Prometheus = require("./Prometheus.res.js");
5
7
  var EntityHistory = require("./db/EntityHistory.res.js");
6
8
  var ErrorHandling = require("./ErrorHandling.res.js");
7
9
  var Caml_exceptions = require("rescript/lib/js/caml_exceptions.js");
@@ -22,7 +24,7 @@ var entityHistoryActionEnumConfig = {
22
24
  default: "SET"
23
25
  };
24
26
 
25
- function make(userEntities, dcRegistryEntityConfig, allEnums, staticTables, storage, cacheStorage, onStorageInitialize) {
27
+ function make(userEntities, dcRegistryEntityConfig, allEnums, staticTables, storage) {
26
28
  var allEntities = userEntities.concat([dcRegistryEntityConfig]);
27
29
  var allEnums$1 = allEnums.concat([entityHistoryActionEnumConfig]);
28
30
  return {
@@ -31,14 +33,21 @@ function make(userEntities, dcRegistryEntityConfig, allEnums, staticTables, stor
31
33
  allEntities: allEntities,
32
34
  allEnums: allEnums$1,
33
35
  storageStatus: "Unknown",
34
- storage: storage,
35
- onStorageInitialize: onStorageInitialize,
36
- cacheStorage: cacheStorage
36
+ storage: storage
37
37
  };
38
38
  }
39
39
 
40
- async function init(persistence, skipIsInitializedCheckOpt, resetOpt) {
41
- var skipIsInitializedCheck = skipIsInitializedCheckOpt !== undefined ? skipIsInitializedCheckOpt : false;
40
+ async function loadInitialCache(persistence, withUpload) {
41
+ var effectCacheRecords = await persistence.storage.restoreEffectCache(withUpload);
42
+ var cache = {};
43
+ effectCacheRecords.forEach(function (record) {
44
+ Prometheus.EffectCacheCount.set(record.count, record.effectName);
45
+ cache[record.effectName] = record;
46
+ });
47
+ return cache;
48
+ }
49
+
50
+ async function init(persistence, resetOpt) {
42
51
  var reset = resetOpt !== undefined ? resetOpt : false;
43
52
  try {
44
53
  var promise = persistence.storageStatus;
@@ -64,20 +73,26 @@ async function init(persistence, skipIsInitializedCheckOpt, resetOpt) {
64
73
  TAG: "Initializing",
65
74
  _0: promise$1
66
75
  };
67
- if (!(reset || skipIsInitializedCheck) && await persistence.storage.isInitialized()) {
76
+ if (reset || !await persistence.storage.isInitialized()) {
77
+ Logging.info("Initializing the indexer storage...");
78
+ await persistence.storage.initialize(persistence.allEntities, persistence.staticTables, persistence.allEnums);
79
+ Logging.info("The indexer storage is ready. Uploading cache...");
68
80
  persistence.storageStatus = {
69
81
  TAG: "Ready",
70
- cleanRun: false
82
+ cleanRun: true,
83
+ cache: await loadInitialCache(persistence, true)
71
84
  };
72
85
  } else {
73
- await persistence.storage.initialize(persistence.allEntities, persistence.staticTables, persistence.allEnums, reset || !skipIsInitializedCheck);
74
- persistence.storageStatus = {
75
- TAG: "Ready",
76
- cleanRun: true
77
- };
78
- var onStorageInitialize = persistence.onStorageInitialize;
79
- if (onStorageInitialize !== undefined) {
80
- await onStorageInitialize();
86
+ var match = persistence.storageStatus;
87
+ var tmp;
88
+ tmp = typeof match !== "object" || match.TAG !== "Initializing" ? false : true;
89
+ if (tmp) {
90
+ Logging.info("The indexer storage is ready.");
91
+ persistence.storageStatus = {
92
+ TAG: "Ready",
93
+ cleanRun: false,
94
+ cache: await loadInitialCache(persistence, false)
95
+ };
81
96
  }
82
97
 
83
98
  }
@@ -98,9 +113,39 @@ function getInitializedStorageOrThrow(persistence) {
98
113
  }
99
114
  }
100
115
 
116
+ async function setEffectCacheOrThrow(persistence, effect, items) {
117
+ var match = persistence.storageStatus;
118
+ if (typeof match !== "object") {
119
+ return Js_exn.raiseError("Failed to access the indexer storage. The Persistence layer is not initialized.");
120
+ }
121
+ if (match.TAG === "Initializing") {
122
+ return Js_exn.raiseError("Failed to access the indexer storage. The Persistence layer is not initialized.");
123
+ }
124
+ var cache = match.cache;
125
+ var storage = persistence.storage;
126
+ var effectName = effect.name;
127
+ var c = cache[effectName];
128
+ var effectCacheRecord;
129
+ if (c !== undefined) {
130
+ effectCacheRecord = c;
131
+ } else {
132
+ var c$1 = {
133
+ effectName: effectName,
134
+ count: 0
135
+ };
136
+ cache[effectName] = c$1;
137
+ effectCacheRecord = c$1;
138
+ }
139
+ var initialize = effectCacheRecord.count === 0;
140
+ await storage.setEffectCacheOrThrow(effect, items, initialize);
141
+ effectCacheRecord.count = effectCacheRecord.count + items.length | 0;
142
+ return Prometheus.EffectCacheCount.set(effectCacheRecord.count, effectName);
143
+ }
144
+
101
145
  exports.StorageError = StorageError;
102
146
  exports.entityHistoryActionEnumConfig = entityHistoryActionEnumConfig;
103
147
  exports.make = make;
104
148
  exports.init = init;
105
149
  exports.getInitializedStorageOrThrow = getInitializedStorageOrThrow;
106
- /* EntityHistory Not a pure module */
150
+ exports.setEffectCacheOrThrow = setEffectCacheOrThrow;
151
+ /* Logging Not a pure module */