envio 3.15.0-subgraph → 3.16.0-subgraph
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/README.md +40 -34
- package/evm.schema.json +3 -3
- package/fuel.schema.json +2 -2
- package/index.d.ts +3 -3
- package/licenses/README.md +1 -1
- package/package.json +8 -8
- package/src/Batch.res.mjs +5 -5
- package/src/BatchProcessing.res +1 -0
- package/src/BatchProcessing.res.mjs +1 -0
- package/src/ChainFetching.res +1 -6
- package/src/ChainFetching.res.mjs +1 -1
- package/src/ChainState.res +48 -7
- package/src/ChainState.res.mjs +21 -8
- package/src/Clock.res +57 -0
- package/src/Clock.res.mjs +72 -0
- package/src/Config.res +16 -4
- package/src/Config.res.mjs +5 -3
- package/src/Core.res +4 -40
- package/src/CrossChainState.res +10 -6
- package/src/CrossChainState.res.mjs +1 -1
- package/src/EffectState.res +10 -2
- package/src/EffectState.res.mjs +8 -4
- package/src/EffectState.resi +3 -1
- package/src/EntityId.res +2 -7
- package/src/EntityId.res.mjs +1 -8
- package/src/EntityTables.res +4 -1
- package/src/EntityTables.res.mjs +1 -1
- package/src/Env.res +4 -0
- package/src/Env.res.mjs +5 -0
- package/src/FetchState.res +157 -69
- package/src/FetchState.res.mjs +112 -47
- package/src/FinalizeBackfill.res +2 -4
- package/src/FinalizeBackfill.res.mjs +3 -4
- package/src/InMemoryTable.res +17 -16
- package/src/InMemoryTable.res.mjs +14 -15
- package/src/IndexerState.res +28 -4
- package/src/IndexerState.res.mjs +19 -6
- package/src/IndexerState.resi +4 -0
- package/src/Internal.res +0 -49
- package/src/Internal.res.mjs +1 -80
- package/src/LoadLayer.res +17 -10
- package/src/LoadLayer.res.mjs +11 -8
- package/src/Main.res.mjs +1 -1
- package/src/Persistence.res +3 -23
- package/src/Persistence.res.mjs +3 -3
- package/src/PreloadLookahead.res +42 -24
- package/src/PreloadLookahead.res.mjs +51 -30
- package/src/Rollback.res +0 -1
- package/src/Rollback.res.mjs +1 -1
- package/src/SafeCheckpointTracking.res +4 -4
- package/src/SafeCheckpointTracking.res.mjs +1 -1
- package/src/StagedRows.res +106 -0
- package/src/StagedRows.res.mjs +102 -0
- package/src/Staging.res +32 -14
- package/src/Staging.res.mjs +17 -20
- package/src/Storage.res +278 -973
- package/src/Storage.res.mjs +218 -720
- package/src/Supervisor.res +75 -56
- package/src/Supervisor.res.mjs +55 -26
- package/src/SyncWrites.res +24 -18
- package/src/SyncWrites.res.mjs +11 -11
- package/src/TestIndexer.res +22 -27
- package/src/TestIndexer.res.mjs +20 -17
- package/src/Throttler.res +15 -8
- package/src/Throttler.res.mjs +9 -6
- package/src/Throttler.resi +1 -1
- package/src/UserContext.res +13 -4
- package/src/UserContext.res.mjs +5 -5
- package/src/Utils.res +0 -6
- package/src/Utils.res.mjs +0 -5
- package/src/Writing.res +0 -1
- package/src/Writing.res.mjs +1 -1
- package/src/bindings/ClickHouse.res +0 -322
- package/src/bindings/ClickHouse.res.mjs +0 -338
- package/src/bindings/StorageClient.res +107 -174
- package/src/bindings/StorageClient.res.mjs +19 -8
- package/src/bindings/Vitest.res +0 -26
- package/src/bindings/Vitest.res.mjs +0 -3
- package/src/db/Table.res +24 -150
- package/src/db/Table.res.mjs +38 -272
- package/src/sources/ChainSources.res +2 -0
- package/src/sources/ChainSources.res.mjs +2 -2
- package/src/sources/EvmChain.res +3 -0
- package/src/sources/EvmChain.res.mjs +4 -2
- package/src/sources/EvmHyperSyncSource.res +2 -2
- package/src/sources/EvmHyperSyncSource.res.mjs +1 -1
- package/src/sources/EvmRpcClient.res +13 -3
- package/src/sources/EvmRpcClient.res.mjs +4 -3
- package/src/sources/EvmRpcWs.res +4 -3
- package/src/sources/EvmRpcWs.res.mjs +2 -2
- package/src/sources/HeightFeed.res +31 -10
- package/src/sources/HeightFeed.res.mjs +10 -6
- package/src/sources/HeightStream.res +32 -17
- package/src/sources/HeightStream.res.mjs +10 -10
- package/src/sources/HyperSyncSSE.res +4 -6
- package/src/sources/HyperSyncSSE.res.mjs +2 -2
- package/src/sources/RpcSource.res +10 -1
- package/src/sources/RpcSource.res.mjs +4 -3
- package/src/sources/Source.res +3 -0
- package/src/sources/SourceManager.res +85 -104
- package/src/sources/SourceManager.res.mjs +18 -37
- package/src/sources/SourceManager.resi +3 -5
- package/src/sources/StartBlockResolver.res +1 -0
- package/src/sources/StartBlockResolver.res.mjs +4 -3
- package/src/sources/SvmHyperSyncSource.res +2 -2
- package/src/sources/SvmHyperSyncSource.res.mjs +1 -1
- package/src/subgraph/graph-ts.ts +87 -28
- package/src/subgraph/runtime.ts +0 -1
- package/src/subgraph/scope.ts +0 -1
- package/svm.schema.json +3 -3
- package/src/PgWriting.res +0 -36
- package/src/PgWriting.res.mjs +0 -34
- package/src/db/IndexDefinition.res +0 -47
- package/src/db/IndexDefinition.res.mjs +0 -60
package/src/TestIndexer.res.mjs
CHANGED
|
@@ -7,7 +7,6 @@ import * as Config from "./Config.res.mjs";
|
|
|
7
7
|
import * as Logger from "./Logger.res.mjs";
|
|
8
8
|
import * as ChainId from "./ChainId.res.mjs";
|
|
9
9
|
import * as ChainMap from "./ChainMap.res.mjs";
|
|
10
|
-
import * as EntityId from "./EntityId.res.mjs";
|
|
11
10
|
import * as Frontier from "./db/Frontier.res.mjs";
|
|
12
11
|
import * as Internal from "./Internal.res.mjs";
|
|
13
12
|
import * as ChainState from "./ChainState.res.mjs";
|
|
@@ -39,11 +38,12 @@ function renderRows(rows, config) {
|
|
|
39
38
|
return AddressRows.render(rows, config.ecosystem.name, !config.lowercaseAddresses);
|
|
40
39
|
}
|
|
41
40
|
|
|
42
|
-
function rowKey(scope, entityId) {
|
|
41
|
+
function rowKey(table, scope, entityId) {
|
|
42
|
+
let entityKey = table.entityIdToKey(entityId);
|
|
43
43
|
if (scope === "crossChain") {
|
|
44
|
-
return
|
|
44
|
+
return entityKey;
|
|
45
45
|
} else {
|
|
46
|
-
return ChainId.toString(scope) + `|` +
|
|
46
|
+
return ChainId.toString(scope) + `|` + entityKey;
|
|
47
47
|
}
|
|
48
48
|
}
|
|
49
49
|
|
|
@@ -126,12 +126,12 @@ function handleWriteBatch(state, config, updatedEntities, registeredAddresses, c
|
|
|
126
126
|
let entity = change.entity;
|
|
127
127
|
let match = Internal.chainScopeChainId(scope);
|
|
128
128
|
let storedEntity = chainIdField !== undefined && match !== undefined ? Internal.stampChainId(entity, chainIdField.fieldName, Primitive_option.valFromOption(match)) : entity;
|
|
129
|
-
entityDict[rowKey(scope, change.entityId)] = storedEntity;
|
|
129
|
+
entityDict[rowKey(entityConfig.table, scope, change.entityId)] = storedEntity;
|
|
130
130
|
entityChangeFor(change.checkpointId).sets.push(entity);
|
|
131
131
|
return;
|
|
132
132
|
}
|
|
133
133
|
let entityId = change.entityId;
|
|
134
|
-
Stdlib_Dict.$$delete(entityDict, rowKey(scope, entityId));
|
|
134
|
+
Stdlib_Dict.$$delete(entityDict, rowKey(entityConfig.table, scope, entityId));
|
|
135
135
|
entityChangeFor(change.checkpointId).deleted.push(entityId);
|
|
136
136
|
};
|
|
137
137
|
param.changes.forEach(processChange);
|
|
@@ -304,11 +304,14 @@ function getEntityFromState(state, entityConfig, entityId, methodName) {
|
|
|
304
304
|
Stdlib_JsError.throwWithMessage(`Cannot call ` + entityConfig.name + `.` + methodName + `() while indexer.process() is running. ` + "Wait for process() to complete before accessing entities directly.");
|
|
305
305
|
}
|
|
306
306
|
let entityDict = Stdlib_Option.getOr(state.entities[entityConfig.name], {});
|
|
307
|
+
let match = entityConfig.table;
|
|
308
|
+
let entityIdToKey = match.entityIdToKey;
|
|
309
|
+
let key = entityIdToKey(entityId);
|
|
307
310
|
let field = Table.getChainIdField(entityConfig.table);
|
|
308
311
|
if (field === undefined) {
|
|
309
|
-
return Stdlib_Option.map(entityDict[
|
|
312
|
+
return Stdlib_Option.map(entityDict[key], copyEntity);
|
|
310
313
|
}
|
|
311
|
-
let matches = Object.values(entityDict).filter(entity => entity.id ===
|
|
314
|
+
let matches = Object.values(entityDict).filter(entity => entityIdToKey(entity.id) === key);
|
|
312
315
|
let len = matches.length;
|
|
313
316
|
if (len !== 1) {
|
|
314
317
|
if (len === 0) {
|
|
@@ -358,7 +361,7 @@ function makeEntitySet(state, entityConfig) {
|
|
|
358
361
|
} else {
|
|
359
362
|
scope = "crossChain";
|
|
360
363
|
}
|
|
361
|
-
entityDict[rowKey(scope, entity.id)] = Utils.Dict.shallowCopy(entity);
|
|
364
|
+
entityDict[rowKey(entityConfig.table, scope, entity.id)] = Utils.Dict.shallowCopy(entity);
|
|
362
365
|
};
|
|
363
366
|
}
|
|
364
367
|
|
|
@@ -388,23 +391,23 @@ function makeInMemoryStorage(state) {
|
|
|
388
391
|
name: "test-inmemory",
|
|
389
392
|
entityStoreName: param => "test-inmemory",
|
|
390
393
|
holding: async () => "Initialized",
|
|
391
|
-
initialize: async (param, param$1, param$2
|
|
394
|
+
initialize: async (param, param$1, param$2) => Stdlib_JsError.throwWithMessage("TestIndexer: initialize should not be called; the initial state is derived from config."),
|
|
392
395
|
readStoredConfig: async () => Stdlib_JsError.throwWithMessage("TestIndexer: readStoredConfig should not be called; the initial state is derived from config."),
|
|
393
|
-
addChain: async (param, param$1
|
|
394
|
-
resumeInitialState: async (param, param$1
|
|
396
|
+
addChain: async (param, param$1) => Stdlib_JsError.throwWithMessage("TestIndexer: addChain should not be called; the initial state is derived from config."),
|
|
397
|
+
resumeInitialState: async (param, param$1) => Stdlib_JsError.throwWithMessage("TestIndexer: resumeInitialState should not be called; the initial state is derived from config."),
|
|
395
398
|
loadOrThrow: async (filter, table) => handleLoad(state, table.tableName, filter),
|
|
396
399
|
ensureQueryIndexes: async (param, param$1, param$2) => {},
|
|
397
|
-
ensureSchemaIndexes: async
|
|
398
|
-
finalizeBackfill: async (param, param$1
|
|
400
|
+
ensureSchemaIndexes: async param => {},
|
|
401
|
+
finalizeBackfill: async (param, param$1) => {},
|
|
399
402
|
dumpEffectCache: async () => {},
|
|
400
403
|
reset: async () => {},
|
|
401
404
|
setChainMeta: async param => {},
|
|
402
405
|
pruneStaleCheckpoints: async param => {},
|
|
403
406
|
pruneStaleEntityHistory: async (param, param$1) => {},
|
|
404
|
-
getRollbackTargetCheckpoint: async (param, param$1
|
|
407
|
+
getRollbackTargetCheckpoint: async (param, param$1) => Stdlib_JsError.throwWithMessage("TestIndexer: Rollback is not supported. The runner forces rollbackOnReorg off, so this should be unreachable."),
|
|
405
408
|
getRollbackProgressDiff: async param => Stdlib_JsError.throwWithMessage("TestIndexer: Rollback is not supported. The runner forces rollbackOnReorg off, so this should be unreachable."),
|
|
406
409
|
getRollbackData: async (param, param$1) => Stdlib_JsError.throwWithMessage("TestIndexer: Rollback is not supported. The runner forces rollbackOnReorg off, so this should be unreachable."),
|
|
407
|
-
writeBatch: async (batch, param, config, param$1,
|
|
410
|
+
writeBatch: async (batch, param, config, param$1, updatedEntities, registeredAddresses, param$2, param$3) => handleWriteBatch(state, config, updatedEntities, registeredAddresses, batch.checkpointIds, batch.checkpointChainIds, batch.checkpointBlockNumbers, batch.checkpointEventsProcessed),
|
|
408
411
|
close: async () => {}
|
|
409
412
|
};
|
|
410
413
|
}
|
|
@@ -648,7 +651,7 @@ function createTestIndexer() {
|
|
|
648
651
|
let indexerState = IndexerState.makeFromDbState(runConfig, logger$1, persistence, initialState, registrationsByChainId, undefined, undefined, exitAfterFirstEventBlock, undefined, undefined, undefined, errHandler => {
|
|
649
652
|
ErrorHandling.log(errHandler);
|
|
650
653
|
reject(ErrorHandling.toExn(errHandler));
|
|
651
|
-
}, () => resolve());
|
|
654
|
+
}, () => resolve(), undefined);
|
|
652
655
|
indexerStateRef.contents = Primitive_option.some(indexerState);
|
|
653
656
|
IndexerLoop.start(indexerState);
|
|
654
657
|
});
|
package/src/Throttler.res
CHANGED
|
@@ -5,27 +5,30 @@ type t = {
|
|
|
5
5
|
mutable scheduled: option<unit => promise<unit>>,
|
|
6
6
|
intervalMillis: float,
|
|
7
7
|
logger: Logger.t,
|
|
8
|
+
clock: Clock.t,
|
|
8
9
|
}
|
|
9
10
|
|
|
10
|
-
let make = (~intervalMillis: int, ~logger) => {
|
|
11
|
-
|
|
11
|
+
let make = (~intervalMillis: int, ~logger, ~clock=Clock.real) => {
|
|
12
|
+
// A clock reads from its own origin, which the first run must not wait on.
|
|
13
|
+
lastRunTimeMillis: -.(intervalMillis->Int.toFloat),
|
|
12
14
|
isRunning: false,
|
|
13
15
|
isAwaitingInterval: false,
|
|
14
16
|
scheduled: None,
|
|
15
17
|
intervalMillis: intervalMillis->Int.toFloat,
|
|
16
18
|
logger,
|
|
19
|
+
clock,
|
|
17
20
|
}
|
|
18
21
|
|
|
19
22
|
let rec startInternal = (throttler: t) => {
|
|
20
23
|
switch throttler {
|
|
21
24
|
| {scheduled: Some(fn), isRunning: false, isAwaitingInterval: false} =>
|
|
22
|
-
let timeSinceLastRun =
|
|
25
|
+
let timeSinceLastRun = throttler.clock.now() -. throttler.lastRunTimeMillis
|
|
23
26
|
|
|
24
27
|
//Only execute if we are passed the interval
|
|
25
28
|
if timeSinceLastRun >= throttler.intervalMillis {
|
|
26
29
|
throttler.isRunning = true
|
|
27
30
|
throttler.scheduled = None
|
|
28
|
-
throttler.lastRunTimeMillis =
|
|
31
|
+
throttler.lastRunTimeMillis = throttler.clock.now()
|
|
29
32
|
|
|
30
33
|
// Defer off the schedule call so work queued before it (e.g. a batch) runs first.
|
|
31
34
|
NodeJs.setImmediate(() => {
|
|
@@ -45,10 +48,14 @@ let rec startInternal = (throttler: t) => {
|
|
|
45
48
|
} else {
|
|
46
49
|
//Store isAwaitingInterval in state so that timers don't continuously get created
|
|
47
50
|
throttler.isAwaitingInterval = true
|
|
48
|
-
let _ = setTimeout(
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
51
|
+
let _ = throttler.clock.setTimeout(
|
|
52
|
+
~label="throttled write",
|
|
53
|
+
() => {
|
|
54
|
+
throttler.isAwaitingInterval = false
|
|
55
|
+
throttler->startInternal
|
|
56
|
+
},
|
|
57
|
+
Int.fromFloat(throttler.intervalMillis -. timeSinceLastRun),
|
|
58
|
+
)
|
|
52
59
|
}
|
|
53
60
|
| _ => ()
|
|
54
61
|
}
|
package/src/Throttler.res.mjs
CHANGED
|
@@ -1,16 +1,19 @@
|
|
|
1
1
|
// Generated by ReScript, PLEASE EDIT WITH CARE
|
|
2
2
|
|
|
3
|
+
import * as Clock from "./Clock.res.mjs";
|
|
3
4
|
import * as Logger from "./Logger.res.mjs";
|
|
4
5
|
import * as Primitive_exceptions from "@rescript/runtime/lib/es6/Primitive_exceptions.js";
|
|
5
6
|
|
|
6
|
-
function make(intervalMillis, logger) {
|
|
7
|
+
function make(intervalMillis, logger, clockOpt) {
|
|
8
|
+
let clock = clockOpt !== undefined ? clockOpt : Clock.real;
|
|
7
9
|
return {
|
|
8
|
-
lastRunTimeMillis:
|
|
10
|
+
lastRunTimeMillis: - intervalMillis,
|
|
9
11
|
isRunning: false,
|
|
10
12
|
isAwaitingInterval: false,
|
|
11
13
|
scheduled: undefined,
|
|
12
14
|
intervalMillis: intervalMillis,
|
|
13
|
-
logger: logger
|
|
15
|
+
logger: logger,
|
|
16
|
+
clock: clock
|
|
14
17
|
};
|
|
15
18
|
}
|
|
16
19
|
|
|
@@ -27,11 +30,11 @@ function startInternal(throttler) {
|
|
|
27
30
|
if (fn === undefined) {
|
|
28
31
|
return;
|
|
29
32
|
}
|
|
30
|
-
let timeSinceLastRun =
|
|
33
|
+
let timeSinceLastRun = throttler.clock.now() - throttler.lastRunTimeMillis;
|
|
31
34
|
if (timeSinceLastRun >= throttler.intervalMillis) {
|
|
32
35
|
throttler.isRunning = true;
|
|
33
36
|
throttler.scheduled = undefined;
|
|
34
|
-
throttler.lastRunTimeMillis =
|
|
37
|
+
throttler.lastRunTimeMillis = throttler.clock.now();
|
|
35
38
|
setImmediate(() => {
|
|
36
39
|
(async () => {
|
|
37
40
|
try {
|
|
@@ -46,7 +49,7 @@ function startInternal(throttler) {
|
|
|
46
49
|
});
|
|
47
50
|
} else {
|
|
48
51
|
throttler.isAwaitingInterval = true;
|
|
49
|
-
setTimeout(() => {
|
|
52
|
+
throttler.clock.setTimeout("throttled write", () => {
|
|
50
53
|
throttler.isAwaitingInterval = false;
|
|
51
54
|
startInternal(throttler);
|
|
52
55
|
}, throttler.intervalMillis - timeSinceLastRun | 0);
|
package/src/Throttler.resi
CHANGED
|
@@ -15,7 +15,7 @@ Does NOT queue scheduled functions but rather overwrites them
|
|
|
15
15
|
The logger will be used to log any errors that occur in the scheduled
|
|
16
16
|
functions.
|
|
17
17
|
*/
|
|
18
|
-
let make: (~intervalMillis: int, ~logger: Logger.t) => t
|
|
18
|
+
let make: (~intervalMillis: int, ~logger: Logger.t, ~clock: Clock.t=?) => t
|
|
19
19
|
|
|
20
20
|
/**
|
|
21
21
|
Schedules a function to be run on a throttler, overwriting any
|
package/src/UserContext.res
CHANGED
|
@@ -390,11 +390,13 @@ let makeEntityContext = (params: params, ~entityConfig: Internal.entityConfig) =
|
|
|
390
390
|
let run = currentRunOrThrow(~prop)
|
|
391
391
|
let sync = run->syncOrThrow(~prop=`${prop}.getSync`)
|
|
392
392
|
let scope = run->scopeOf
|
|
393
|
+
// The lookahead keys an entity as its writes do, a Bytes id by its hex.
|
|
394
|
+
let entityKey = entityConfig.table.entityIdToKey(entityId->EntityId.unsafeOfString)
|
|
393
395
|
switch sync.writes->SyncWrites.getById(~entityConfig, ~entityId) {
|
|
394
396
|
| Some(entity) => entity
|
|
395
397
|
| None =>
|
|
396
398
|
switch run.isPreload
|
|
397
|
-
? PreloadLookahead.overlayGet(~item=run.item, ~entityName, ~scope, ~entityId)
|
|
399
|
+
? PreloadLookahead.overlayGet(~item=run.item, ~entityName, ~scope, ~entityId=entityKey)
|
|
398
400
|
: None {
|
|
399
401
|
| Some(entity) => entity
|
|
400
402
|
| None =>
|
|
@@ -406,7 +408,12 @@ let makeEntityContext = (params: params, ~entityConfig: Internal.entityConfig) =
|
|
|
406
408
|
) {
|
|
407
409
|
| Some(entity) =>
|
|
408
410
|
if run.isPreload && entity->Option.isNone {
|
|
409
|
-
PreloadLookahead.recordAbsent(
|
|
411
|
+
PreloadLookahead.recordAbsent(
|
|
412
|
+
~item=run.item,
|
|
413
|
+
~entityName,
|
|
414
|
+
~scope,
|
|
415
|
+
~entityId=entityKey,
|
|
416
|
+
)
|
|
410
417
|
}
|
|
411
418
|
entity
|
|
412
419
|
| None =>
|
|
@@ -464,7 +471,9 @@ let makeEntityContext = (params: params, ~entityConfig: Internal.entityConfig) =
|
|
|
464
471
|
| None =>
|
|
465
472
|
let inMemTable =
|
|
466
473
|
params.indexerState->InMemoryStore.getInMemTable(~entityConfig, ~scope=run->scopeOf)
|
|
467
|
-
switch inMemTable.latestEntityChangeById->Utils.Dict.dangerouslyGetNonOption(
|
|
474
|
+
switch inMemTable.latestEntityChangeById->Utils.Dict.dangerouslyGetNonOption(
|
|
475
|
+
inMemTable.entityIdToKey(entityId->EntityId.unsafeOfString),
|
|
476
|
+
) {
|
|
468
477
|
| Some(change) if change->Change.getCheckpointId == run.checkpointId =>
|
|
469
478
|
change->InMemoryTable.Entity.mapChangeToEntity
|
|
470
479
|
| _ => None
|
|
@@ -527,7 +536,7 @@ let rec runSyncRound = async (params: params, sync: syncRun, fn: unit => unit, ~
|
|
|
527
536
|
~item=run.item,
|
|
528
537
|
~entityName=entityConfig.name,
|
|
529
538
|
~scope,
|
|
530
|
-
~entityId=change->Change.getEntityId
|
|
539
|
+
~entityId=entityConfig.table.entityIdToKey(change->Change.getEntityId),
|
|
531
540
|
~entity=change->InMemoryTable.Entity.mapChangeToEntity,
|
|
532
541
|
)
|
|
533
542
|
)
|
package/src/UserContext.res.mjs
CHANGED
|
@@ -4,7 +4,6 @@ import * as Env from "./Env.res.mjs";
|
|
|
4
4
|
import * as Utils from "./Utils.res.mjs";
|
|
5
5
|
import * as Logger from "./Logger.res.mjs";
|
|
6
6
|
import * as ChainId from "./ChainId.res.mjs";
|
|
7
|
-
import * as EntityId from "./EntityId.res.mjs";
|
|
8
7
|
import * as Internal from "./Internal.res.mjs";
|
|
9
8
|
import * as RunScope from "./RunScope.res.mjs";
|
|
10
9
|
import * as LoadLayer from "./LoadLayer.res.mjs";
|
|
@@ -275,11 +274,12 @@ function makeEntityContext(params, entityConfig) {
|
|
|
275
274
|
let run = currentRunOrThrow(prop);
|
|
276
275
|
let sync = syncOrThrow(run, prop + `.getSync`);
|
|
277
276
|
let scope = scopeOf(run);
|
|
277
|
+
let entityKey = entityConfig.table.entityIdToKey(entityId);
|
|
278
278
|
let entity = SyncWrites.getById(sync.writes, entityConfig, entityId);
|
|
279
279
|
if (entity !== undefined) {
|
|
280
280
|
return Primitive_option.valFromOption(entity);
|
|
281
281
|
}
|
|
282
|
-
let entity$1 = run.isPreload ? PreloadLookahead.overlayGet(run.item, entityName, scope,
|
|
282
|
+
let entity$1 = run.isPreload ? PreloadLookahead.overlayGet(run.item, entityName, scope, entityKey) : undefined;
|
|
283
283
|
if (entity$1 !== undefined) {
|
|
284
284
|
return Primitive_option.valFromOption(entity$1);
|
|
285
285
|
}
|
|
@@ -289,7 +289,7 @@ function makeEntityContext(params, entityConfig) {
|
|
|
289
289
|
}
|
|
290
290
|
let entity$3 = Primitive_option.valFromOption(entity$2);
|
|
291
291
|
if (run.isPreload && Stdlib_Option.isNone(entity$3)) {
|
|
292
|
-
PreloadLookahead.recordAbsent(run.item, entityName, scope,
|
|
292
|
+
PreloadLookahead.recordAbsent(run.item, entityName, scope, entityKey);
|
|
293
293
|
}
|
|
294
294
|
return entity$3;
|
|
295
295
|
};
|
|
@@ -313,7 +313,7 @@ function makeEntityContext(params, entityConfig) {
|
|
|
313
313
|
return Primitive_option.valFromOption(entity);
|
|
314
314
|
}
|
|
315
315
|
let inMemTable = InMemoryStore.getInMemTable(params.indexerState, entityConfig, scopeOf(run));
|
|
316
|
-
let change = inMemTable.latestEntityChangeById[entityId];
|
|
316
|
+
let change = inMemTable.latestEntityChangeById[inMemTable.entityIdToKey(entityId)];
|
|
317
317
|
if (change !== undefined && change.checkpointId === run.checkpointId) {
|
|
318
318
|
return InMemoryTable.Entity.mapChangeToEntity(change);
|
|
319
319
|
}
|
|
@@ -361,7 +361,7 @@ async function runSyncRound(params, sync, fn, round) {
|
|
|
361
361
|
let match = sync.status;
|
|
362
362
|
if (typeof match !== "object" && sync.speculated <= 0) {
|
|
363
363
|
if (run.isPreload) {
|
|
364
|
-
SyncWrites.forEachChange(writes, (entityConfig, scope, change) => PreloadLookahead.overlaySet(run.item, entityConfig.name, scope,
|
|
364
|
+
SyncWrites.forEachChange(writes, (entityConfig, scope, change) => PreloadLookahead.overlaySet(run.item, entityConfig.name, scope, entityConfig.table.entityIdToKey(change.entityId), InMemoryTable.Entity.mapChangeToEntity(change)));
|
|
365
365
|
} else {
|
|
366
366
|
SyncWrites.commit(writes, params.indexerState);
|
|
367
367
|
}
|
package/src/Utils.res
CHANGED
|
@@ -10,12 +10,6 @@ external toMethod: 'a => 'a = "%unsafe_to_method"
|
|
|
10
10
|
|
|
11
11
|
@val external importPath: string => promise<unknown> = "import"
|
|
12
12
|
|
|
13
|
-
// Half the delay fixed, half spread across it. Every indexer pointed at one
|
|
14
|
-
// provider loses its stream, or gives up on a quiet chain, in the same instant
|
|
15
|
-
// that provider blinks, and putting them all back on the same schedule is how a
|
|
16
|
-
// blip becomes a stampede.
|
|
17
|
-
let jitter = delay => delay / 2 + (Math.random() *. (delay / 2)->Int.toFloat)->Float.toInt
|
|
18
|
-
|
|
19
13
|
// Clearing a pending timer and forgetting it are one action. A ref left holding
|
|
20
14
|
// a spent id reads as a timer still pending, and the next clear looks like it
|
|
21
15
|
// did something.
|
package/src/Utils.res.mjs
CHANGED
|
@@ -14,10 +14,6 @@ import * as Primitive_string from "@rescript/runtime/lib/es6/Primitive_string.js
|
|
|
14
14
|
import * as S$RescriptSchema from "rescript-schema/src/S.res.mjs";
|
|
15
15
|
import * as Primitive_exceptions from "@rescript/runtime/lib/es6/Primitive_exceptions.js";
|
|
16
16
|
|
|
17
|
-
function jitter(delay) {
|
|
18
|
-
return (delay / 2 | 0) + (Math.random() * (delay / 2 | 0) | 0) | 0;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
17
|
function clearTimeoutRef(timeoutId) {
|
|
22
18
|
let id = timeoutId.contents;
|
|
23
19
|
if (id !== undefined) {
|
|
@@ -824,7 +820,6 @@ function replaceLoneSurrogateEscapes(json) {
|
|
|
824
820
|
let maxBackoffExponent = 20;
|
|
825
821
|
|
|
826
822
|
export {
|
|
827
|
-
jitter,
|
|
828
823
|
clearTimeoutRef,
|
|
829
824
|
maxBackoffExponent,
|
|
830
825
|
expBackoff,
|
package/src/Writing.res
CHANGED
package/src/Writing.res.mjs
CHANGED
|
@@ -121,7 +121,7 @@ async function runOneWrite(state) {
|
|
|
121
121
|
});
|
|
122
122
|
let pruneTargets = PruneStaleHistory.select(state, writtenEntityNames, Stdlib_Option.isSome(rollback));
|
|
123
123
|
await Promise.all([
|
|
124
|
-
persistence.storage.writeBatch(batch, rollback, config,
|
|
124
|
+
persistence.storage.writeBatch(batch, rollback, config, updatedEffectsCache, updatedEntities, registeredAddresses, chainMetaData, (storage, timeSeconds) => IndexerState.recordStorageWrite(state, storage, timeSeconds)),
|
|
125
125
|
PruneStaleHistory.runConcurrent(state, pruneTargets)
|
|
126
126
|
]);
|
|
127
127
|
IndexerState.markCommitted(state, writtenFrontier);
|