Skip to content

Commit 46cd378

Browse files
committed
Simulate add/remove event registration in repoGetValue
1 parent db50631 commit 46cd378

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

packages/database/src/core/Repo.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ import {
4848
statsManagerGetOrCreateReporter
4949
} from './stats/StatsManager';
5050
import { StatsReporter, statsReporterIncludeStat } from './stats/StatsReporter';
51-
import { syncPointGetView, syncPointViewExistsForQuery, syncPointViewForQuery } from './SyncPoint';
51+
import { syncPointGetView, syncPointIsEmpty, syncPointViewExistsForQuery, syncPointViewForQuery } from './SyncPoint';
5252
import {
5353
createNewTag,
5454
SyncTree,
@@ -483,9 +483,15 @@ export function repoGetValue(repo: Repo, query: QueryContext): Promise<Node> {
483483
);
484484
eventQueueRaiseEventsAtPath(repo.eventQueue_, query._path, events);
485485
} else {
486-
// Otherwise, only overwrite for query
487-
console.log('query')
488-
syncTreeAddToPath(query, repo.serverSyncTree_);
486+
// Simulate `syncTreeAddEventRegistration` without events/listener setup.
487+
// TODO: We can probably extract this.
488+
const { syncPoint, serverCache, writesCache, serverCacheComplete, viewAlreadyExists, foundAncestorDefaultView } = syncTreeAddToPath(query, repo.serverSyncTree_);
489+
if (!viewAlreadyExists && !foundAncestorDefaultView) {
490+
const view = syncPointGetView(syncPoint, query, writesCache, serverCache, serverCacheComplete);
491+
if (!syncPoint.views.has(query._queryIdentifier)) {
492+
syncPoint.views.set(query._queryIdentifier, view);
493+
}
494+
}
489495
const tag = syncTreeTagForQuery_(repo.serverSyncTree_, query);
490496
const events = syncTreeApplyTaggedQueryOverwrite(
491497
repo.serverSyncTree_,
@@ -494,6 +500,9 @@ export function repoGetValue(repo: Repo, query: QueryContext): Promise<Node> {
494500
tag
495501
);
496502
eventQueueRaiseEventsAtPath(repo.eventQueue_, query._path, events);
503+
// Call `syncTreeRemoveEventRegistration` with a null event registration, since there is none.
504+
const cancels = syncTreeRemoveEventRegistration(repo.serverSyncTree_, query, null)
505+
assert(cancels.length == 0, "unexpected cancel events in repoGetValue");
497506
}
498507
return Promise.resolve(node);
499508
},

0 commit comments

Comments
 (0)