Skip to content

Commit 81dcd76

Browse files
committed
fix(data): shared-record gates for search inserts, write-refresh views, and persistence
- collectRecords: remove the empty per-entity Map so records.has() returns false once no view holds records, preventing late or post-eviction searches from inserting rows no view evaluates. - confirm (refreshed): include every entry sharing entity names with the adopted entries in the commit, matching what touchWithViews does for load and restore, so views see records a write's search updated. - save: when a non-view entry with entities is saved, also mark views of those entities for persistence, so the shared table they persist from stays in sync across restarts.
1 parent 86fa474 commit 81dcd76

1 file changed

Lines changed: 20 additions & 4 deletions

File tree

‎packages/octane/src/data/store.ts‎

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -340,8 +340,14 @@ export function createDataStore(options: DataStoreOptions): DataStore {
340340
/** Save an entry once its confirmed value changes; a view's change is every view's of its entity. */
341341
function save(entry: Entry): void {
342342
if (!persisted) return;
343-
if (!isView(entry.read)) persisted.mark(entry.key);
344-
else for (const view of viewEntries(entry.read.view.of.name)) persisted.mark(view.key);
343+
if (!isView(entry.read)) {
344+
persisted.mark(entry.key);
345+
for (const name of entry.names) {
346+
for (const view of viewEntries(name)) persisted.mark(view.key);
347+
}
348+
} else {
349+
for (const view of viewEntries(entry.read.view.of.name)) persisted.mark(view.key);
350+
}
345351
}
346352

347353
/** The confirmed records within a view's span, in its order. */
@@ -445,6 +451,7 @@ export function createDataStore(options: DataStoreOptions): DataStore {
445451
for (const [id, record] of table) {
446452
if (!views.some((entry) => inSpan(entry, record.value))) table.delete(id);
447453
}
454+
if (table.size === 0) records.delete(name);
448455
}
449456

450457
/**
@@ -1053,8 +1060,17 @@ export function createDataStore(options: DataStoreOptions): DataStore {
10531060
// One reply is one server transaction: adopt every value, then notify.
10541061
if (pending.length > 0) {
10551062
void Promise.all(pending).then((commits) => {
1056-
const adopted = commits.map((adopt) => adopt());
1057-
commit(adopted.filter((entry): entry is Entry => entry !== undefined));
1063+
const adopted = commits.map((fn) => fn());
1064+
const direct = adopted.filter((entry): entry is Entry => entry !== undefined);
1065+
const changed = new Set(direct);
1066+
for (const entry of direct) {
1067+
for (const name of entry.names) {
1068+
for (const other of entries.values()) {
1069+
if (!changed.has(other) && other.names.has(name)) changed.add(other);
1070+
}
1071+
}
1072+
}
1073+
commit(changed);
10581074
});
10591075
}
10601076
const tags = writeTags(operation.write);

0 commit comments

Comments
 (0)