@rocicorp/zero 0.26.0-canary.7 → 0.26.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/out/ast-to-zql/src/ast-to-zql.d.ts.map +1 -1
- package/out/ast-to-zql/src/ast-to-zql.js +16 -27
- package/out/ast-to-zql/src/ast-to-zql.js.map +1 -1
- package/out/otel/src/log-options.d.ts +2 -2
- package/out/replicache/src/bg-interval.d.ts.map +1 -1
- package/out/replicache/src/bg-interval.js +3 -0
- package/out/replicache/src/bg-interval.js.map +1 -1
- package/out/shared/src/arrays.js +1 -1
- package/out/shared/src/arrays.js.map +1 -1
- package/out/shared/src/browser-env.js +0 -4
- package/out/shared/src/browser-env.js.map +1 -1
- package/out/shared/src/btree-set.js +4 -1
- package/out/shared/src/btree-set.js.map +1 -1
- package/out/shared/src/options.js +1 -1
- package/out/shared/src/options.js.map +1 -1
- package/out/shared/src/queue.js +1 -1
- package/out/shared/src/queue.js.map +1 -1
- package/out/z2s/src/compiler.d.ts.map +1 -1
- package/out/z2s/src/compiler.js +13 -11
- package/out/z2s/src/compiler.js.map +1 -1
- package/out/zero/package.json.js +1 -1
- package/out/zero/src/react.js +1 -3
- package/out/zero/src/react.js.map +1 -1
- package/out/zero-cache/src/auth/read-authorizer.js +0 -7
- package/out/zero-cache/src/auth/read-authorizer.js.map +1 -1
- package/out/zero-cache/src/config/network.d.ts +3 -2
- package/out/zero-cache/src/config/network.d.ts.map +1 -1
- package/out/zero-cache/src/config/network.js +9 -2
- package/out/zero-cache/src/config/network.js.map +1 -1
- package/out/zero-cache/src/config/server-context.d.ts +16 -0
- package/out/zero-cache/src/config/server-context.d.ts.map +1 -0
- package/out/zero-cache/src/config/server-context.js +32 -0
- package/out/zero-cache/src/config/server-context.js.map +1 -0
- package/out/zero-cache/src/config/zero-config.d.ts +3 -3
- package/out/zero-cache/src/config/zero-config.d.ts.map +1 -1
- package/out/zero-cache/src/config/zero-config.js +2 -6
- package/out/zero-cache/src/config/zero-config.js.map +1 -1
- package/out/zero-cache/src/db/migration.d.ts.map +1 -1
- package/out/zero-cache/src/db/migration.js +40 -51
- package/out/zero-cache/src/db/migration.js.map +1 -1
- package/out/zero-cache/src/db/run-transaction.d.ts +17 -0
- package/out/zero-cache/src/db/run-transaction.d.ts.map +1 -0
- package/out/zero-cache/src/db/run-transaction.js +24 -0
- package/out/zero-cache/src/db/run-transaction.js.map +1 -0
- package/out/zero-cache/src/db/transaction-pool.d.ts.map +1 -1
- package/out/zero-cache/src/db/transaction-pool.js +3 -3
- package/out/zero-cache/src/db/transaction-pool.js.map +1 -1
- package/out/zero-cache/src/scripts/decommission.d.ts +1 -1
- package/out/zero-cache/src/scripts/deploy-permissions.js +2 -1
- package/out/zero-cache/src/scripts/deploy-permissions.js.map +1 -1
- package/out/zero-cache/src/scripts/permissions.d.ts +1 -1
- package/out/zero-cache/src/server/change-streamer.d.ts.map +1 -1
- package/out/zero-cache/src/server/change-streamer.js +6 -2
- package/out/zero-cache/src/server/change-streamer.js.map +1 -1
- package/out/zero-cache/src/server/main.js +1 -1
- package/out/zero-cache/src/server/main.js.map +1 -1
- package/out/zero-cache/src/server/runner/run-worker.d.ts.map +1 -1
- package/out/zero-cache/src/server/runner/run-worker.js +7 -3
- package/out/zero-cache/src/server/runner/run-worker.js.map +1 -1
- package/out/zero-cache/src/services/change-source/common/backfill-manager.d.ts +1 -1
- package/out/zero-cache/src/services/change-source/common/backfill-manager.d.ts.map +1 -1
- package/out/zero-cache/src/services/change-source/common/backfill-manager.js +11 -9
- package/out/zero-cache/src/services/change-source/common/backfill-manager.js.map +1 -1
- package/out/zero-cache/src/services/change-source/common/replica-schema.d.ts.map +1 -1
- package/out/zero-cache/src/services/change-source/common/replica-schema.js +11 -0
- package/out/zero-cache/src/services/change-source/common/replica-schema.js.map +1 -1
- package/out/zero-cache/src/services/change-source/custom/change-source.d.ts +5 -2
- package/out/zero-cache/src/services/change-source/custom/change-source.d.ts.map +1 -1
- package/out/zero-cache/src/services/change-source/custom/change-source.js +6 -6
- package/out/zero-cache/src/services/change-source/custom/change-source.js.map +1 -1
- package/out/zero-cache/src/services/change-source/pg/change-source.d.ts +6 -4
- package/out/zero-cache/src/services/change-source/pg/change-source.d.ts.map +1 -1
- package/out/zero-cache/src/services/change-source/pg/change-source.js +148 -54
- package/out/zero-cache/src/services/change-source/pg/change-source.js.map +1 -1
- package/out/zero-cache/src/services/change-source/pg/decommission.d.ts.map +1 -1
- package/out/zero-cache/src/services/change-source/pg/decommission.js +2 -1
- package/out/zero-cache/src/services/change-source/pg/decommission.js.map +1 -1
- package/out/zero-cache/src/services/change-source/pg/initial-sync.d.ts +4 -1
- package/out/zero-cache/src/services/change-source/pg/initial-sync.d.ts.map +1 -1
- package/out/zero-cache/src/services/change-source/pg/initial-sync.js +35 -10
- package/out/zero-cache/src/services/change-source/pg/initial-sync.js.map +1 -1
- package/out/zero-cache/src/services/change-source/pg/logical-replication/stream.js +1 -1
- package/out/zero-cache/src/services/change-source/pg/logical-replication/stream.js.map +1 -1
- package/out/zero-cache/src/services/change-source/pg/schema/init.d.ts.map +1 -1
- package/out/zero-cache/src/services/change-source/pg/schema/init.js +10 -0
- package/out/zero-cache/src/services/change-source/pg/schema/init.js.map +1 -1
- package/out/zero-cache/src/services/change-source/pg/schema/shard.d.ts +6 -3
- package/out/zero-cache/src/services/change-source/pg/schema/shard.d.ts.map +1 -1
- package/out/zero-cache/src/services/change-source/pg/schema/shard.js +19 -10
- package/out/zero-cache/src/services/change-source/pg/schema/shard.js.map +1 -1
- package/out/zero-cache/src/services/change-source/protocol/current/data.d.ts +1 -0
- package/out/zero-cache/src/services/change-source/protocol/current/data.d.ts.map +1 -1
- package/out/zero-cache/src/services/change-source/protocol/current/data.js +4 -2
- package/out/zero-cache/src/services/change-source/protocol/current/data.js.map +1 -1
- package/out/zero-cache/src/services/change-source/protocol/current/downstream.d.ts +3 -0
- package/out/zero-cache/src/services/change-source/protocol/current/downstream.d.ts.map +1 -1
- package/out/zero-cache/src/services/change-source/protocol/current/status.d.ts +6 -4
- package/out/zero-cache/src/services/change-source/protocol/current/status.d.ts.map +1 -1
- package/out/zero-cache/src/services/change-source/protocol/current/status.js.map +1 -1
- package/out/zero-cache/src/services/change-streamer/backup-monitor.d.ts +2 -2
- package/out/zero-cache/src/services/change-streamer/backup-monitor.d.ts.map +1 -1
- package/out/zero-cache/src/services/change-streamer/backup-monitor.js +30 -12
- package/out/zero-cache/src/services/change-streamer/backup-monitor.js.map +1 -1
- package/out/zero-cache/src/services/change-streamer/change-streamer-service.js +23 -3
- package/out/zero-cache/src/services/change-streamer/change-streamer-service.js.map +1 -1
- package/out/zero-cache/src/services/change-streamer/change-streamer.d.ts +1 -0
- package/out/zero-cache/src/services/change-streamer/change-streamer.d.ts.map +1 -1
- package/out/zero-cache/src/services/change-streamer/forwarder.js +1 -1
- package/out/zero-cache/src/services/change-streamer/forwarder.js.map +1 -1
- package/out/zero-cache/src/services/change-streamer/schema/tables.d.ts +1 -1
- package/out/zero-cache/src/services/change-streamer/schema/tables.d.ts.map +1 -1
- package/out/zero-cache/src/services/change-streamer/schema/tables.js +12 -4
- package/out/zero-cache/src/services/change-streamer/schema/tables.js.map +1 -1
- package/out/zero-cache/src/services/change-streamer/storer.d.ts +11 -2
- package/out/zero-cache/src/services/change-streamer/storer.d.ts.map +1 -1
- package/out/zero-cache/src/services/change-streamer/storer.js +80 -42
- package/out/zero-cache/src/services/change-streamer/storer.js.map +1 -1
- package/out/zero-cache/src/services/litestream/commands.d.ts +1 -1
- package/out/zero-cache/src/services/litestream/commands.d.ts.map +1 -1
- package/out/zero-cache/src/services/litestream/commands.js +2 -1
- package/out/zero-cache/src/services/litestream/commands.js.map +1 -1
- package/out/zero-cache/src/services/mutagen/mutagen.d.ts.map +1 -1
- package/out/zero-cache/src/services/mutagen/mutagen.js +22 -17
- package/out/zero-cache/src/services/mutagen/mutagen.js.map +1 -1
- package/out/zero-cache/src/services/replicator/schema/replication-state.d.ts +10 -1
- package/out/zero-cache/src/services/replicator/schema/replication-state.d.ts.map +1 -1
- package/out/zero-cache/src/services/replicator/schema/replication-state.js +49 -9
- package/out/zero-cache/src/services/replicator/schema/replication-state.js.map +1 -1
- package/out/zero-cache/src/services/running-state.d.ts +1 -0
- package/out/zero-cache/src/services/running-state.d.ts.map +1 -1
- package/out/zero-cache/src/services/running-state.js +3 -0
- package/out/zero-cache/src/services/running-state.js.map +1 -1
- package/out/zero-cache/src/services/view-syncer/cvr-purger.d.ts.map +1 -1
- package/out/zero-cache/src/services/view-syncer/cvr-purger.js +32 -28
- package/out/zero-cache/src/services/view-syncer/cvr-purger.js.map +1 -1
- package/out/zero-cache/src/services/view-syncer/cvr-store.d.ts.map +1 -1
- package/out/zero-cache/src/services/view-syncer/cvr-store.js +329 -155
- package/out/zero-cache/src/services/view-syncer/cvr-store.js.map +1 -1
- package/out/zero-cache/src/services/view-syncer/cvr.d.ts.map +1 -1
- package/out/zero-cache/src/services/view-syncer/cvr.js +387 -345
- package/out/zero-cache/src/services/view-syncer/cvr.js.map +1 -1
- package/out/zero-cache/src/services/view-syncer/pipeline-driver.d.ts.map +1 -1
- package/out/zero-cache/src/services/view-syncer/pipeline-driver.js +68 -16
- package/out/zero-cache/src/services/view-syncer/pipeline-driver.js.map +1 -1
- package/out/zero-cache/src/services/view-syncer/row-record-cache.d.ts.map +1 -1
- package/out/zero-cache/src/services/view-syncer/row-record-cache.js +13 -8
- package/out/zero-cache/src/services/view-syncer/row-record-cache.js.map +1 -1
- package/out/zero-cache/src/services/view-syncer/tracer.d.ts +2 -0
- package/out/zero-cache/src/services/view-syncer/tracer.d.ts.map +1 -0
- package/out/zero-cache/src/services/view-syncer/tracer.js +7 -0
- package/out/zero-cache/src/services/view-syncer/tracer.js.map +1 -0
- package/out/zero-cache/src/services/view-syncer/view-syncer.d.ts.map +1 -1
- package/out/zero-cache/src/services/view-syncer/view-syncer.js +58 -43
- package/out/zero-cache/src/services/view-syncer/view-syncer.js.map +1 -1
- package/out/zero-cache/src/types/pg.js +0 -4
- package/out/zero-cache/src/types/pg.js.map +1 -1
- package/out/zero-cache/src/types/streams.d.ts +3 -1
- package/out/zero-cache/src/types/streams.d.ts.map +1 -1
- package/out/zero-cache/src/types/streams.js +1 -1
- package/out/zero-cache/src/types/streams.js.map +1 -1
- package/out/zero-cache/src/types/subscription.d.ts +7 -1
- package/out/zero-cache/src/types/subscription.d.ts.map +1 -1
- package/out/zero-cache/src/types/subscription.js +8 -2
- package/out/zero-cache/src/types/subscription.js.map +1 -1
- package/out/zero-client/src/client/options.d.ts +7 -7
- package/out/zero-client/src/client/options.d.ts.map +1 -1
- package/out/zero-client/src/client/options.js.map +1 -1
- package/out/zero-client/src/client/query-manager.js +1 -1
- package/out/zero-client/src/client/query-manager.js.map +1 -1
- package/out/zero-client/src/client/version.js +1 -1
- package/out/zero-client/src/client/zero-poke-handler.d.ts +5 -5
- package/out/zero-client/src/client/zero-poke-handler.d.ts.map +1 -1
- package/out/zero-client/src/client/zero-poke-handler.js +15 -17
- package/out/zero-client/src/client/zero-poke-handler.js.map +1 -1
- package/out/zero-client/src/client/zero.d.ts +6 -2
- package/out/zero-client/src/client/zero.d.ts.map +1 -1
- package/out/zero-client/src/client/zero.js +44 -8
- package/out/zero-client/src/client/zero.js.map +1 -1
- package/out/zero-client/src/mod.d.ts +1 -1
- package/out/zero-client/src/mod.d.ts.map +1 -1
- package/out/zero-protocol/src/ast.d.ts +2 -9
- package/out/zero-protocol/src/ast.d.ts.map +1 -1
- package/out/zero-protocol/src/ast.js +15 -32
- package/out/zero-protocol/src/ast.js.map +1 -1
- package/out/zero-protocol/src/protocol-version.d.ts +1 -1
- package/out/zero-protocol/src/protocol-version.d.ts.map +1 -1
- package/out/zero-protocol/src/protocol-version.js +5 -2
- package/out/zero-protocol/src/protocol-version.js.map +1 -1
- package/out/zero-react/src/mod.d.ts +0 -2
- package/out/zero-react/src/mod.d.ts.map +1 -1
- package/out/zero-react/src/use-query.d.ts +6 -6
- package/out/zero-react/src/use-query.d.ts.map +1 -1
- package/out/zero-react/src/use-query.js +9 -2
- package/out/zero-react/src/use-query.js.map +1 -1
- package/out/zero-react/src/zero-provider.d.ts +5 -5
- package/out/zero-react/src/zero-provider.d.ts.map +1 -1
- package/out/zero-react/src/zero-provider.js.map +1 -1
- package/out/zero-solid/src/solid-view.d.ts +0 -42
- package/out/zero-solid/src/solid-view.d.ts.map +1 -1
- package/out/zero-solid/src/solid-view.js +1 -1
- package/out/zero-solid/src/solid-view.js.map +1 -1
- package/out/zero-solid/src/use-query.d.ts +4 -4
- package/out/zero-solid/src/use-query.d.ts.map +1 -1
- package/out/zero-solid/src/use-query.js.map +1 -1
- package/out/zero-solid/src/use-zero.d.ts +5 -5
- package/out/zero-solid/src/use-zero.d.ts.map +1 -1
- package/out/zero-solid/src/use-zero.js.map +1 -1
- package/out/zero-types/src/default-types.d.ts +2 -0
- package/out/zero-types/src/default-types.d.ts.map +1 -1
- package/out/zql/src/builder/builder.d.ts.map +1 -1
- package/out/zql/src/builder/builder.js +6 -48
- package/out/zql/src/builder/builder.js.map +1 -1
- package/out/zql/src/builder/filter.d.ts.map +1 -1
- package/out/zql/src/builder/filter.js +0 -1
- package/out/zql/src/builder/filter.js.map +1 -1
- package/out/zql/src/ivm/array-view.d.ts.map +1 -1
- package/out/zql/src/ivm/array-view.js +6 -57
- package/out/zql/src/ivm/array-view.js.map +1 -1
- package/out/zql/src/ivm/view-apply-change.d.ts +3 -50
- package/out/zql/src/ivm/view-apply-change.d.ts.map +1 -1
- package/out/zql/src/ivm/view-apply-change.js +105 -358
- package/out/zql/src/ivm/view-apply-change.js.map +1 -1
- package/out/zql/src/mutate/mutator-registry.d.ts +3 -3
- package/out/zql/src/mutate/mutator-registry.d.ts.map +1 -1
- package/out/zql/src/mutate/mutator-registry.js.map +1 -1
- package/out/zql/src/planner/planner-builder.d.ts.map +1 -1
- package/out/zql/src/planner/planner-builder.js +1 -2
- package/out/zql/src/planner/planner-builder.js.map +1 -1
- package/out/zql/src/query/complete-ordering.js +0 -6
- package/out/zql/src/query/complete-ordering.js.map +1 -1
- package/out/zql/src/query/expression.d.ts +2 -19
- package/out/zql/src/query/expression.d.ts.map +1 -1
- package/out/zql/src/query/expression.js +6 -50
- package/out/zql/src/query/expression.js.map +1 -1
- package/out/zql/src/query/query-delegate-base.js +3 -1
- package/out/zql/src/query/query-delegate-base.js.map +1 -1
- package/out/zql/src/query/query-impl.d.ts.map +1 -1
- package/out/zql/src/query/query-impl.js +8 -12
- package/out/zql/src/query/query-impl.js.map +1 -1
- package/out/zql/src/query/query-internals.js.map +1 -1
- package/out/zql/src/query/query-registry.d.ts +3 -3
- package/out/zql/src/query/query-registry.d.ts.map +1 -1
- package/out/zql/src/query/query-registry.js.map +1 -1
- package/out/zql/src/query/query.d.ts +28 -5
- package/out/zql/src/query/query.d.ts.map +1 -1
- package/out/zqlite/src/query-builder.d.ts +0 -2
- package/out/zqlite/src/query-builder.d.ts.map +1 -1
- package/out/zqlite/src/query-builder.js.map +1 -1
- package/out/zqlite/src/resolve-scalar-subqueries.d.ts +10 -2
- package/out/zqlite/src/resolve-scalar-subqueries.d.ts.map +1 -1
- package/out/zqlite/src/resolve-scalar-subqueries.js +41 -9
- package/out/zqlite/src/resolve-scalar-subqueries.js.map +1 -1
- package/out/zqlite/src/sqlite-cost-model.d.ts.map +1 -1
- package/out/zqlite/src/sqlite-cost-model.js +0 -1
- package/out/zqlite/src/sqlite-cost-model.js.map +1 -1
- package/package.json +3 -5
- package/out/zero-cache/src/services/change-source/custom/sync-schema.d.ts +0 -4
- package/out/zero-cache/src/services/change-source/custom/sync-schema.d.ts.map +0 -1
- package/out/zero-cache/src/services/change-source/custom/sync-schema.js +0 -14
- package/out/zero-cache/src/services/change-source/custom/sync-schema.js.map +0 -1
- package/out/zero-cache/src/services/change-source/pg/sync-schema.d.ts +0 -5
- package/out/zero-cache/src/services/change-source/pg/sync-schema.d.ts.map +0 -1
- package/out/zero-cache/src/services/change-source/pg/sync-schema.js +0 -14
- package/out/zero-cache/src/services/change-source/pg/sync-schema.js.map +0 -1
- package/out/zero-react/src/paging-reducer.d.ts +0 -61
- package/out/zero-react/src/paging-reducer.d.ts.map +0 -1
- package/out/zero-react/src/paging-reducer.js +0 -77
- package/out/zero-react/src/paging-reducer.js.map +0 -1
- package/out/zero-react/src/use-rows.d.ts +0 -39
- package/out/zero-react/src/use-rows.d.ts.map +0 -1
- package/out/zero-react/src/use-rows.js +0 -130
- package/out/zero-react/src/use-rows.js.map +0 -1
- package/out/zero-react/src/use-zero-virtualizer.d.ts +0 -122
- package/out/zero-react/src/use-zero-virtualizer.d.ts.map +0 -1
- package/out/zero-react/src/use-zero-virtualizer.js +0 -342
- package/out/zero-react/src/use-zero-virtualizer.js.map +0 -1
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { startSpan, startAsyncSpan } from "../../../../otel/src/span.js";
|
|
1
2
|
import { assert } from "../../../../shared/src/asserts.js";
|
|
2
3
|
import "../../../../shared/src/bigint-json.js";
|
|
3
4
|
import { CustomKeyMap } from "../../../../shared/src/custom-key-map.js";
|
|
@@ -13,6 +14,7 @@ import { rowIDString } from "../../types/row-key.js";
|
|
|
13
14
|
import { upstreamSchema } from "../../types/shards.js";
|
|
14
15
|
import "./cvr-store.js";
|
|
15
16
|
import { cmpVersions, maxVersion, oneAfter } from "./schema/types.js";
|
|
17
|
+
import { tracer } from "./tracer.js";
|
|
16
18
|
import { ttlClockAsNumber } from "./ttl-clock.js";
|
|
17
19
|
const CLIENT_LMID_QUERY_ID = "lmids";
|
|
18
20
|
const CLIENT_MUTATION_RESULTS_QUERY_ID = "mutationResults";
|
|
@@ -105,70 +107,71 @@ class CVRConfigDrivenUpdater extends CVRUpdater {
|
|
|
105
107
|
this.#shard = shard;
|
|
106
108
|
}
|
|
107
109
|
ensureClient(id) {
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
110
|
+
return startSpan(tracer, "CVRConfigDrivenUpdater.ensureClient", () => {
|
|
111
|
+
let client = this._cvr.clients[id];
|
|
112
|
+
if (client) {
|
|
113
|
+
return client;
|
|
114
|
+
}
|
|
115
|
+
client = { id, desiredQueryIDs: [] };
|
|
116
|
+
this._cvr.clients[id] = client;
|
|
117
|
+
this._ensureNewVersion();
|
|
118
|
+
this._cvrStore.insertClient(client);
|
|
119
|
+
if (!this._cvr.queries[CLIENT_LMID_QUERY_ID]) {
|
|
120
|
+
const lmidsQuery = {
|
|
121
|
+
id: CLIENT_LMID_QUERY_ID,
|
|
122
|
+
ast: {
|
|
123
|
+
schema: "",
|
|
124
|
+
table: `${upstreamSchema(this.#shard)}.clients`,
|
|
125
|
+
where: {
|
|
126
|
+
type: "simple",
|
|
127
|
+
left: {
|
|
128
|
+
type: "column",
|
|
129
|
+
name: "clientGroupID"
|
|
130
|
+
},
|
|
131
|
+
op: "=",
|
|
132
|
+
right: {
|
|
133
|
+
type: "literal",
|
|
134
|
+
value: this._cvr.id
|
|
135
|
+
}
|
|
127
136
|
},
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
}
|
|
137
|
+
orderBy: [
|
|
138
|
+
["clientGroupID", "asc"],
|
|
139
|
+
["clientID", "asc"]
|
|
140
|
+
]
|
|
133
141
|
},
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
upstreamSchema(this.#shard),
|
|
147
|
-
this._cvr.id
|
|
148
|
-
);
|
|
149
|
-
this._cvr.queries[CLIENT_MUTATION_RESULTS_QUERY_ID] = mutationResultsQuery;
|
|
150
|
-
this._cvrStore.putQuery(mutationResultsQuery);
|
|
151
|
-
}
|
|
152
|
-
return client;
|
|
142
|
+
type: "internal"
|
|
143
|
+
};
|
|
144
|
+
this._cvr.queries[CLIENT_LMID_QUERY_ID] = lmidsQuery;
|
|
145
|
+
this._cvrStore.putQuery(lmidsQuery);
|
|
146
|
+
}
|
|
147
|
+
if (!this._cvr.queries[CLIENT_MUTATION_RESULTS_QUERY_ID]) {
|
|
148
|
+
const mutationResultsQuery = getMutationResultsQuery(upstreamSchema(this.#shard), this._cvr.id);
|
|
149
|
+
this._cvr.queries[CLIENT_MUTATION_RESULTS_QUERY_ID] = mutationResultsQuery;
|
|
150
|
+
this._cvrStore.putQuery(mutationResultsQuery);
|
|
151
|
+
}
|
|
152
|
+
return client;
|
|
153
|
+
});
|
|
153
154
|
}
|
|
154
155
|
setClientSchema(lc, clientSchema) {
|
|
155
|
-
|
|
156
|
-
this._cvr.clientSchema
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
156
|
+
startSpan(tracer, "CVRConfigDrivenUpdater.setClientSchema", () => {
|
|
157
|
+
if (this._cvr.clientSchema === null) {
|
|
158
|
+
this._cvr.clientSchema = clientSchema;
|
|
159
|
+
this._cvrStore.putInstance(this._cvr);
|
|
160
|
+
} else if (!deepEqual(this._cvr.clientSchema, clientSchema)) {
|
|
161
|
+
lc.warn?.(
|
|
162
|
+
`New schema ${JSON.stringify(
|
|
163
|
+
clientSchema
|
|
164
|
+
)} does not match existing schema ${JSON.stringify(
|
|
165
|
+
this._cvr.clientSchema
|
|
166
|
+
)}`
|
|
167
|
+
);
|
|
168
|
+
throw new ProtocolError({
|
|
169
|
+
kind: "InvalidConnectionRequest",
|
|
170
|
+
message: `Provided schema does not match previous schema`,
|
|
171
|
+
origin: ZeroCache
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
});
|
|
172
175
|
}
|
|
173
176
|
setProfileID(lc, profileID) {
|
|
174
177
|
if (this._cvr.profileID !== profileID) {
|
|
@@ -182,72 +185,74 @@ class CVRConfigDrivenUpdater extends CVRUpdater {
|
|
|
182
185
|
}
|
|
183
186
|
}
|
|
184
187
|
putDesiredQueries(clientID, queries) {
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
const
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
const
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
188
|
+
return startSpan(tracer, "CVRConfigDrivenUpdater.putDesiredQueries", () => {
|
|
189
|
+
const patches = [];
|
|
190
|
+
const client = this.ensureClient(clientID);
|
|
191
|
+
const current = new Set(client.desiredQueryIDs);
|
|
192
|
+
const needed = /* @__PURE__ */ new Set();
|
|
193
|
+
const recordQueryForTelemetry = (q) => {
|
|
194
|
+
const { ast, name, args } = q;
|
|
195
|
+
if (ast) {
|
|
196
|
+
recordQuery("crud");
|
|
197
|
+
} else if (name && args) {
|
|
198
|
+
recordQuery("custom");
|
|
199
|
+
}
|
|
200
|
+
};
|
|
201
|
+
for (const q of queries) {
|
|
202
|
+
const { hash, ttl = DEFAULT_TTL_MS } = q;
|
|
203
|
+
const query = this._cvr.queries[hash];
|
|
204
|
+
if (!query) {
|
|
205
|
+
recordQueryForTelemetry(q);
|
|
206
|
+
needed.add(hash);
|
|
207
|
+
continue;
|
|
208
|
+
}
|
|
209
|
+
if (query.type === "internal") {
|
|
210
|
+
continue;
|
|
211
|
+
}
|
|
212
|
+
const oldClientState = query.clientState[clientID];
|
|
213
|
+
if (!oldClientState || oldClientState.inactivatedAt !== void 0) {
|
|
214
|
+
recordQueryForTelemetry(q);
|
|
215
|
+
needed.add(hash);
|
|
216
|
+
continue;
|
|
217
|
+
}
|
|
218
|
+
if (compareTTL(ttl, oldClientState.ttl) > 0) {
|
|
219
|
+
needed.add(hash);
|
|
220
|
+
}
|
|
207
221
|
}
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
recordQueryForTelemetry(q);
|
|
211
|
-
needed.add(hash);
|
|
212
|
-
continue;
|
|
222
|
+
if (needed.size === 0) {
|
|
223
|
+
return patches;
|
|
213
224
|
}
|
|
214
|
-
|
|
215
|
-
|
|
225
|
+
const newVersion = this._ensureNewVersion();
|
|
226
|
+
client.desiredQueryIDs = [...union(current, needed)].sort(stringCompare);
|
|
227
|
+
for (const id of needed) {
|
|
228
|
+
const q = must(queries.find(({ hash }) => hash === id));
|
|
229
|
+
const { ast, name, args } = q;
|
|
230
|
+
const ttl = clampTTL(q.ttl ?? DEFAULT_TTL_MS);
|
|
231
|
+
const query = this._cvr.queries[id] ?? newQueryRecord(id, ast, name, args);
|
|
232
|
+
assertNotInternal(query);
|
|
233
|
+
const inactivatedAt = void 0;
|
|
234
|
+
query.clientState[clientID] = {
|
|
235
|
+
inactivatedAt,
|
|
236
|
+
ttl,
|
|
237
|
+
version: newVersion
|
|
238
|
+
};
|
|
239
|
+
this._cvr.queries[id] = query;
|
|
240
|
+
patches.push({
|
|
241
|
+
toVersion: newVersion,
|
|
242
|
+
patch: { type: "query", op: "put", id, clientID }
|
|
243
|
+
});
|
|
244
|
+
this._cvrStore.putQuery(query);
|
|
245
|
+
this._cvrStore.putDesiredQuery(
|
|
246
|
+
newVersion,
|
|
247
|
+
query,
|
|
248
|
+
client,
|
|
249
|
+
false,
|
|
250
|
+
inactivatedAt,
|
|
251
|
+
ttl
|
|
252
|
+
);
|
|
216
253
|
}
|
|
217
|
-
}
|
|
218
|
-
if (needed.size === 0) {
|
|
219
254
|
return patches;
|
|
220
|
-
}
|
|
221
|
-
const newVersion = this._ensureNewVersion();
|
|
222
|
-
client.desiredQueryIDs = [...union(current, needed)].sort(stringCompare);
|
|
223
|
-
for (const id of needed) {
|
|
224
|
-
const q = must(queries.find(({ hash }) => hash === id));
|
|
225
|
-
const { ast, name, args } = q;
|
|
226
|
-
const ttl = clampTTL(q.ttl ?? DEFAULT_TTL_MS);
|
|
227
|
-
const query = this._cvr.queries[id] ?? newQueryRecord(id, ast, name, args);
|
|
228
|
-
assertNotInternal(query);
|
|
229
|
-
const inactivatedAt = void 0;
|
|
230
|
-
query.clientState[clientID] = {
|
|
231
|
-
inactivatedAt,
|
|
232
|
-
ttl,
|
|
233
|
-
version: newVersion
|
|
234
|
-
};
|
|
235
|
-
this._cvr.queries[id] = query;
|
|
236
|
-
patches.push({
|
|
237
|
-
toVersion: newVersion,
|
|
238
|
-
patch: { type: "query", op: "put", id, clientID }
|
|
239
|
-
});
|
|
240
|
-
this._cvrStore.putQuery(query);
|
|
241
|
-
this._cvrStore.putDesiredQuery(
|
|
242
|
-
newVersion,
|
|
243
|
-
query,
|
|
244
|
-
client,
|
|
245
|
-
false,
|
|
246
|
-
inactivatedAt,
|
|
247
|
-
ttl
|
|
248
|
-
);
|
|
249
|
-
}
|
|
250
|
-
return patches;
|
|
255
|
+
});
|
|
251
256
|
}
|
|
252
257
|
markDesiredQueriesAsInactive(clientID, queryHashes, ttlClock) {
|
|
253
258
|
return this.#deleteQueries(clientID, queryHashes, ttlClock);
|
|
@@ -256,75 +261,79 @@ class CVRConfigDrivenUpdater extends CVRUpdater {
|
|
|
256
261
|
return this.#deleteQueries(clientID, queryHashes, void 0);
|
|
257
262
|
}
|
|
258
263
|
#deleteQueries(clientID, queryHashes, inactivatedAt) {
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
const newVersion = this._ensureNewVersion();
|
|
268
|
-
client.desiredQueryIDs = [...difference(current, remove)].sort(
|
|
269
|
-
stringCompare
|
|
270
|
-
);
|
|
271
|
-
for (const id of remove) {
|
|
272
|
-
const query = this._cvr.queries[id];
|
|
273
|
-
if (!query) {
|
|
274
|
-
continue;
|
|
264
|
+
return startSpan(tracer, "CVRConfigDrivenUpdater.#deleteQueries", () => {
|
|
265
|
+
const patches = [];
|
|
266
|
+
const client = this.ensureClient(clientID);
|
|
267
|
+
const current = new Set(client.desiredQueryIDs);
|
|
268
|
+
const unwanted = new Set(queryHashes);
|
|
269
|
+
const remove = intersection(unwanted, current);
|
|
270
|
+
if (remove.size === 0) {
|
|
271
|
+
return patches;
|
|
275
272
|
}
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
const
|
|
282
|
-
if (
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
query.clientState[clientID]
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
273
|
+
const newVersion = this._ensureNewVersion();
|
|
274
|
+
client.desiredQueryIDs = [...difference(current, remove)].sort(
|
|
275
|
+
stringCompare
|
|
276
|
+
);
|
|
277
|
+
for (const id of remove) {
|
|
278
|
+
const query = this._cvr.queries[id];
|
|
279
|
+
if (!query) {
|
|
280
|
+
continue;
|
|
281
|
+
}
|
|
282
|
+
assertNotInternal(query);
|
|
283
|
+
let ttl = DEFAULT_TTL_MS;
|
|
284
|
+
if (inactivatedAt === void 0) {
|
|
285
|
+
delete query.clientState[clientID];
|
|
286
|
+
} else {
|
|
287
|
+
const clientState = query.clientState[clientID];
|
|
288
|
+
if (clientState !== void 0) {
|
|
289
|
+
assert(
|
|
290
|
+
clientState.inactivatedAt === void 0,
|
|
291
|
+
`Query ${id} is already inactivated`
|
|
292
|
+
);
|
|
293
|
+
ttl = clampTTL(clientState.ttl);
|
|
294
|
+
query.clientState[clientID] = {
|
|
295
|
+
inactivatedAt,
|
|
296
|
+
ttl,
|
|
297
|
+
version: newVersion
|
|
298
|
+
};
|
|
299
|
+
}
|
|
293
300
|
}
|
|
301
|
+
this._cvrStore.putQuery(query);
|
|
302
|
+
this._cvrStore.putDesiredQuery(
|
|
303
|
+
newVersion,
|
|
304
|
+
query,
|
|
305
|
+
client,
|
|
306
|
+
true,
|
|
307
|
+
inactivatedAt,
|
|
308
|
+
ttl
|
|
309
|
+
);
|
|
310
|
+
patches.push({
|
|
311
|
+
toVersion: newVersion,
|
|
312
|
+
patch: { type: "query", op: "del", id, clientID }
|
|
313
|
+
});
|
|
294
314
|
}
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
newVersion,
|
|
298
|
-
query,
|
|
299
|
-
client,
|
|
300
|
-
true,
|
|
301
|
-
inactivatedAt,
|
|
302
|
-
ttl
|
|
303
|
-
);
|
|
304
|
-
patches.push({
|
|
305
|
-
toVersion: newVersion,
|
|
306
|
-
patch: { type: "query", op: "del", id, clientID }
|
|
307
|
-
});
|
|
308
|
-
}
|
|
309
|
-
return patches;
|
|
315
|
+
return patches;
|
|
316
|
+
});
|
|
310
317
|
}
|
|
311
318
|
clearDesiredQueries(clientID) {
|
|
312
319
|
const client = this.ensureClient(clientID);
|
|
313
320
|
return this.#deleteQueries(clientID, client.desiredQueryIDs, void 0);
|
|
314
321
|
}
|
|
315
322
|
deleteClient(clientID, ttlClock) {
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
323
|
+
return startSpan(tracer, "CVRConfigDrivenUpdater.deleteClient", () => {
|
|
324
|
+
const client = this._cvr.clients[clientID];
|
|
325
|
+
if (!client) {
|
|
326
|
+
return [];
|
|
327
|
+
}
|
|
328
|
+
const patches = this.markDesiredQueriesAsInactive(
|
|
329
|
+
clientID,
|
|
330
|
+
client.desiredQueryIDs,
|
|
331
|
+
ttlClock
|
|
332
|
+
);
|
|
333
|
+
delete this._cvr.clients[clientID];
|
|
334
|
+
this._cvrStore.deleteClient(clientID);
|
|
335
|
+
return patches;
|
|
336
|
+
});
|
|
328
337
|
}
|
|
329
338
|
}
|
|
330
339
|
class CVRQueryDrivenUpdater extends CVRUpdater {
|
|
@@ -368,48 +377,56 @@ class CVRQueryDrivenUpdater extends CVRUpdater {
|
|
|
368
377
|
* @returns The new CVRVersion to be used when all changes are committed.
|
|
369
378
|
*/
|
|
370
379
|
trackQueries(lc, executed, removed) {
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
380
|
+
return startSpan(tracer, "CVRQueryDrivenUpdater.trackQueries", () => {
|
|
381
|
+
assert(this.#existingRows === void 0, `trackQueries already called`);
|
|
382
|
+
const queryPatches = [
|
|
383
|
+
executed.map((q) => this.#trackExecuted(q.id, q.transformationHash)),
|
|
384
|
+
removed.map((q) => this.#trackRemoved(q.id))
|
|
385
|
+
].flat(2);
|
|
386
|
+
this.#existingRows = this.#lookupRowsForExecutedAndRemovedQueries(lc);
|
|
387
|
+
void this.#existingRows.then(() => {
|
|
388
|
+
});
|
|
389
|
+
return {
|
|
390
|
+
newVersion: this._cvr.version,
|
|
391
|
+
queryPatches: queryPatches.map((patch) => ({
|
|
392
|
+
patch,
|
|
393
|
+
toVersion: this._cvr.version
|
|
394
|
+
}))
|
|
395
|
+
};
|
|
378
396
|
});
|
|
379
|
-
return {
|
|
380
|
-
newVersion: this._cvr.version,
|
|
381
|
-
queryPatches: queryPatches.map((patch) => ({
|
|
382
|
-
patch,
|
|
383
|
-
toVersion: this._cvr.version
|
|
384
|
-
}))
|
|
385
|
-
};
|
|
386
397
|
}
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
398
|
+
#lookupRowsForExecutedAndRemovedQueries(lc) {
|
|
399
|
+
return startAsyncSpan(
|
|
400
|
+
tracer,
|
|
401
|
+
"CVRQueryDrivenUpdater.#lookupRowsForExecutedAndRemovedQueries",
|
|
402
|
+
async () => {
|
|
403
|
+
const results = new CustomKeyMap(rowIDString);
|
|
404
|
+
if (this.#removedOrExecutedQueryIDs.size === 0) {
|
|
405
|
+
return [];
|
|
406
|
+
}
|
|
407
|
+
const allRowRecords = (await this._cvrStore.getRowRecords()).values();
|
|
408
|
+
let total = 0;
|
|
409
|
+
for (const existing of allRowRecords) {
|
|
410
|
+
total++;
|
|
411
|
+
assert(
|
|
412
|
+
existing.refCounts !== null,
|
|
413
|
+
"allRowRecords should not include null refCounts"
|
|
414
|
+
);
|
|
415
|
+
for (const id of Object.keys(existing.refCounts)) {
|
|
416
|
+
if (this.#removedOrExecutedQueryIDs.has(id)) {
|
|
417
|
+
results.set(existing.id, existing);
|
|
418
|
+
break;
|
|
419
|
+
}
|
|
420
|
+
}
|
|
404
421
|
}
|
|
422
|
+
lc.debug?.(
|
|
423
|
+
`found ${results.size} (of ${total}) rows for executed / removed queries ${[
|
|
424
|
+
...this.#removedOrExecutedQueryIDs
|
|
425
|
+
]}`
|
|
426
|
+
);
|
|
427
|
+
return results.values();
|
|
405
428
|
}
|
|
406
|
-
}
|
|
407
|
-
lc.debug?.(
|
|
408
|
-
`found ${results.size} (of ${total}) rows for executed / removed queries ${[
|
|
409
|
-
...this.#removedOrExecutedQueryIDs
|
|
410
|
-
]}`
|
|
411
429
|
);
|
|
412
|
-
return results.values();
|
|
413
430
|
}
|
|
414
431
|
/**
|
|
415
432
|
* Tracks an executed query, ensures that it is marked as "gotten",
|
|
@@ -418,28 +435,30 @@ class CVRQueryDrivenUpdater extends CVRUpdater {
|
|
|
418
435
|
* This must be called for all executed queries.
|
|
419
436
|
*/
|
|
420
437
|
#trackExecuted(queryID, transformationHash) {
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
query.patchVersion
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
438
|
+
return startSpan(tracer, "CVRQueryDrivenUpdater.#trackExecuted", () => {
|
|
439
|
+
assert(
|
|
440
|
+
!this.#removedOrExecutedQueryIDs.has(queryID),
|
|
441
|
+
() => `Query ${queryID} already tracked as executed or removed`
|
|
442
|
+
);
|
|
443
|
+
this.#removedOrExecutedQueryIDs.add(queryID);
|
|
444
|
+
let gotQueryPatch;
|
|
445
|
+
const query = this._cvr.queries[queryID];
|
|
446
|
+
if (query.transformationHash !== transformationHash) {
|
|
447
|
+
const transformationVersion = this._ensureNewVersion();
|
|
448
|
+
if (query.type !== "internal" && query.patchVersion === void 0) {
|
|
449
|
+
query.patchVersion = transformationVersion;
|
|
450
|
+
gotQueryPatch = {
|
|
451
|
+
type: "query",
|
|
452
|
+
op: "put",
|
|
453
|
+
id: query.id
|
|
454
|
+
};
|
|
455
|
+
}
|
|
456
|
+
query.transformationHash = transformationHash;
|
|
457
|
+
query.transformationVersion = transformationVersion;
|
|
458
|
+
this._cvrStore.updateQuery(query);
|
|
437
459
|
}
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
this._cvrStore.updateQuery(query);
|
|
441
|
-
}
|
|
442
|
-
return gotQueryPatch ? [gotQueryPatch] : [];
|
|
460
|
+
return gotQueryPatch ? [gotQueryPatch] : [];
|
|
461
|
+
});
|
|
443
462
|
}
|
|
444
463
|
/**
|
|
445
464
|
* Tracks a query removed from the "gotten" set. In addition to producing the
|
|
@@ -452,18 +471,20 @@ class CVRQueryDrivenUpdater extends CVRUpdater {
|
|
|
452
471
|
* This must only be called on queries that are not "desired" by any client.
|
|
453
472
|
*/
|
|
454
473
|
#trackRemoved(queryID) {
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
474
|
+
return startSpan(tracer, "CVRQueryDrivenUpdater.#trackRemoved", () => {
|
|
475
|
+
const query = this._cvr.queries[queryID];
|
|
476
|
+
assertNotInternal(query);
|
|
477
|
+
assert(
|
|
478
|
+
!this.#removedOrExecutedQueryIDs.has(queryID),
|
|
479
|
+
() => `Query ${queryID} already tracked as executed or removed`
|
|
480
|
+
);
|
|
481
|
+
this.#removedOrExecutedQueryIDs.add(queryID);
|
|
482
|
+
delete this._cvr.queries[queryID];
|
|
483
|
+
const newVersion = this._ensureNewVersion();
|
|
484
|
+
const queryPatch = { type: "query", op: "del", id: queryID };
|
|
485
|
+
this._cvrStore.markQueryAsDeleted(newVersion, queryPatch);
|
|
486
|
+
return [queryPatch];
|
|
487
|
+
});
|
|
467
488
|
}
|
|
468
489
|
/**
|
|
469
490
|
* Asserts that a new version has already been set.
|
|
@@ -486,65 +507,74 @@ class CVRQueryDrivenUpdater extends CVRUpdater {
|
|
|
486
507
|
* returns (put) patches to be returned to update their state, versioned by
|
|
487
508
|
* patchVersion so that only the patches new to the clients are sent.
|
|
488
509
|
*/
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
rowVersion
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
const lastPatch = this.#lastPatches.get(id);
|
|
516
|
-
const toVersion = maxVersion(patchVersion, lastPatch?.toVersion);
|
|
517
|
-
if (merged === null) {
|
|
518
|
-
if (existing || previouslyReceived) {
|
|
519
|
-
if (lastPatch?.rowVersion !== null) {
|
|
520
|
-
patches.push({
|
|
521
|
-
patch: {
|
|
522
|
-
type: "row",
|
|
523
|
-
op: "del",
|
|
524
|
-
id
|
|
525
|
-
},
|
|
526
|
-
toVersion
|
|
510
|
+
received(_lc, rows) {
|
|
511
|
+
return startAsyncSpan(
|
|
512
|
+
tracer,
|
|
513
|
+
"CVRQueryDrivenUpdater.received",
|
|
514
|
+
async () => {
|
|
515
|
+
const patches = [];
|
|
516
|
+
const existingRows = await this._cvrStore.getRowRecords();
|
|
517
|
+
for (const [id, update] of rows.entries()) {
|
|
518
|
+
const { contents, version, refCounts } = update;
|
|
519
|
+
let existing = existingRows.get(id);
|
|
520
|
+
const previouslyReceived = this.#receivedRows.get(id);
|
|
521
|
+
const merged = previouslyReceived !== void 0 ? mergeRefCounts(previouslyReceived, refCounts) : mergeRefCounts(
|
|
522
|
+
existing?.refCounts,
|
|
523
|
+
refCounts,
|
|
524
|
+
this.#removedOrExecutedQueryIDs
|
|
525
|
+
);
|
|
526
|
+
this.#receivedRows.set(id, merged);
|
|
527
|
+
const newRowVersion = merged === null ? void 0 : version;
|
|
528
|
+
const patchVersion = existing && existing.rowVersion === newRowVersion ? existing.patchVersion : this.#assertNewVersion();
|
|
529
|
+
const rowVersion = version ?? existing?.rowVersion;
|
|
530
|
+
if (rowVersion) {
|
|
531
|
+
this._cvrStore.putRowRecord({
|
|
532
|
+
id,
|
|
533
|
+
rowVersion,
|
|
534
|
+
patchVersion,
|
|
535
|
+
refCounts: merged
|
|
527
536
|
});
|
|
528
|
-
|
|
537
|
+
} else {
|
|
538
|
+
this._cvrStore.delRowRecord(id);
|
|
539
|
+
}
|
|
540
|
+
const lastPatch = this.#lastPatches.get(id);
|
|
541
|
+
const toVersion = maxVersion(patchVersion, lastPatch?.toVersion);
|
|
542
|
+
if (merged === null) {
|
|
543
|
+
if (existing || previouslyReceived) {
|
|
544
|
+
if (lastPatch?.rowVersion !== null) {
|
|
545
|
+
patches.push({
|
|
546
|
+
patch: {
|
|
547
|
+
type: "row",
|
|
548
|
+
op: "del",
|
|
549
|
+
id
|
|
550
|
+
},
|
|
551
|
+
toVersion
|
|
552
|
+
});
|
|
553
|
+
this.#lastPatches.set(id, { rowVersion: null, toVersion });
|
|
554
|
+
}
|
|
555
|
+
}
|
|
556
|
+
} else if (contents) {
|
|
557
|
+
assert(
|
|
558
|
+
rowVersion,
|
|
559
|
+
"rowVersion is required when contents is present"
|
|
560
|
+
);
|
|
561
|
+
if (!lastPatch?.rowVersion || lastPatch.rowVersion < rowVersion) {
|
|
562
|
+
patches.push({
|
|
563
|
+
patch: {
|
|
564
|
+
type: "row",
|
|
565
|
+
op: "put",
|
|
566
|
+
id,
|
|
567
|
+
contents
|
|
568
|
+
},
|
|
569
|
+
toVersion
|
|
570
|
+
});
|
|
571
|
+
this.#lastPatches.set(id, { rowVersion, toVersion });
|
|
572
|
+
}
|
|
529
573
|
}
|
|
530
574
|
}
|
|
531
|
-
|
|
532
|
-
assert(rowVersion, "rowVersion is required when contents is present");
|
|
533
|
-
if (!lastPatch?.rowVersion || lastPatch.rowVersion < rowVersion) {
|
|
534
|
-
patches.push({
|
|
535
|
-
patch: {
|
|
536
|
-
type: "row",
|
|
537
|
-
op: "put",
|
|
538
|
-
id,
|
|
539
|
-
contents
|
|
540
|
-
},
|
|
541
|
-
toVersion
|
|
542
|
-
});
|
|
543
|
-
this.#lastPatches.set(id, { rowVersion, toVersion });
|
|
544
|
-
}
|
|
575
|
+
return patches;
|
|
545
576
|
}
|
|
546
|
-
|
|
547
|
-
return patches;
|
|
577
|
+
);
|
|
548
578
|
}
|
|
549
579
|
/**
|
|
550
580
|
* Computes and updates the row records based on:
|
|
@@ -558,49 +588,61 @@ class CVRQueryDrivenUpdater extends CVRUpdater {
|
|
|
558
588
|
* This is Step [5] of the
|
|
559
589
|
* [CVR Sync Algorithm](https://www.notion.so/replicache/Sync-and-Client-View-Records-CVR-a18e02ec3ec543449ea22070855ff33d?pvs=4#7874f9b80a514be2b8cd5cf538b88d37).
|
|
560
590
|
*/
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
591
|
+
deleteUnreferencedRows(lc) {
|
|
592
|
+
return startAsyncSpan(
|
|
593
|
+
tracer,
|
|
594
|
+
"CVRQueryDrivenUpdater.deleteUnreferencedRows",
|
|
595
|
+
async () => {
|
|
596
|
+
if (this.#removedOrExecutedQueryIDs.size === 0) {
|
|
597
|
+
assert(
|
|
598
|
+
this.#receivedRows.size === 0,
|
|
599
|
+
() => `Expected no received rows for query-less update, got ${this.#receivedRows.size}`
|
|
600
|
+
);
|
|
601
|
+
return [];
|
|
602
|
+
}
|
|
603
|
+
const patches = [];
|
|
604
|
+
const start = Date.now();
|
|
605
|
+
assert(this.#existingRows, `trackQueries() was not called`);
|
|
606
|
+
for (const existing of await this.#existingRows) {
|
|
607
|
+
const deletedID = this.#deleteUnreferencedRow(existing);
|
|
608
|
+
if (deletedID === null) {
|
|
609
|
+
continue;
|
|
610
|
+
}
|
|
611
|
+
patches.push({
|
|
612
|
+
toVersion: this._cvr.version,
|
|
613
|
+
patch: { type: "row", op: "del", id: deletedID }
|
|
614
|
+
});
|
|
615
|
+
}
|
|
616
|
+
lc?.debug?.(
|
|
617
|
+
`computed ${patches.length} delete patches (${Date.now() - start} ms)`
|
|
618
|
+
);
|
|
619
|
+
return patches;
|
|
576
620
|
}
|
|
577
|
-
patches.push({
|
|
578
|
-
toVersion: this._cvr.version,
|
|
579
|
-
patch: { type: "row", op: "del", id: deletedID }
|
|
580
|
-
});
|
|
581
|
-
}
|
|
582
|
-
lc?.debug?.(
|
|
583
|
-
`computed ${patches.length} delete patches (${Date.now() - start} ms)`
|
|
584
621
|
);
|
|
585
|
-
return patches;
|
|
586
622
|
}
|
|
587
623
|
#deleteUnreferencedRow(existing) {
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
624
|
+
return startSpan(
|
|
625
|
+
tracer,
|
|
626
|
+
"CVRQueryDrivenUpdater.#deleteUnreferencedRow",
|
|
627
|
+
() => {
|
|
628
|
+
if (this.#receivedRows.get(existing.id)) {
|
|
629
|
+
return null;
|
|
630
|
+
}
|
|
631
|
+
const newRefCounts = mergeRefCounts(
|
|
632
|
+
existing.refCounts,
|
|
633
|
+
void 0,
|
|
634
|
+
this.#removedOrExecutedQueryIDs
|
|
635
|
+
);
|
|
636
|
+
const patchVersion = newRefCounts ? existing.patchVersion : this.#assertNewVersion();
|
|
637
|
+
const rowRecord = {
|
|
638
|
+
...existing,
|
|
639
|
+
patchVersion,
|
|
640
|
+
refCounts: newRefCounts
|
|
641
|
+
};
|
|
642
|
+
this._cvrStore.putRowRecord(rowRecord);
|
|
643
|
+
return newRefCounts ? null : existing.id;
|
|
644
|
+
}
|
|
595
645
|
);
|
|
596
|
-
const patchVersion = newRefCounts ? existing.patchVersion : this.#assertNewVersion();
|
|
597
|
-
const rowRecord = {
|
|
598
|
-
...existing,
|
|
599
|
-
patchVersion,
|
|
600
|
-
refCounts: newRefCounts
|
|
601
|
-
};
|
|
602
|
-
this._cvrStore.putRowRecord(rowRecord);
|
|
603
|
-
return newRefCounts ? null : existing.id;
|
|
604
646
|
}
|
|
605
647
|
}
|
|
606
648
|
function mergeRefCounts(existing, received, removeHashes) {
|