Commit 98ddd13
committed
multiGet: prefer cache over stale storage on concurrent writes
Mirrors the existing prefer-cache check in get() (lib/OnyxUtils.ts
around line 299). Before this change, if a concurrent set/merge
populated cache while multiGet's Storage.multiGet was in flight, the
trailing cache.merge(temp) would fastMerge the stale storage snapshot
on top of the fresher cache value — resurrecting fields the
concurrent write meant to drop.
Per-key check at the storage-result loop: if cache.hasCacheForKey is
true at the time we'd write, take the cached value into dataMap and
skip writing to temp. cache.merge(temp) at the end then only touches
keys that stayed genuinely cold throughout the read.
Adds a regression test under `multiGet cache hit consistency` that
sets the cache from inside the Storage.multiGet mock (synchronously,
before the promise resolves), then asserts both the returned dataMap
and the in-memory cache reflect the concurrent write — not the stale
storage snapshot. Fails without the lib change, passes with it.1 parent 2f9fb8a commit 98ddd13
2 files changed
Lines changed: 28 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
402 | 402 | | |
403 | 403 | | |
404 | 404 | | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
405 | 412 | | |
406 | 413 | | |
407 | 414 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1174 | 1174 | | |
1175 | 1175 | | |
1176 | 1176 | | |
| 1177 | + | |
| 1178 | + | |
| 1179 | + | |
| 1180 | + | |
| 1181 | + | |
| 1182 | + | |
| 1183 | + | |
| 1184 | + | |
| 1185 | + | |
| 1186 | + | |
| 1187 | + | |
| 1188 | + | |
| 1189 | + | |
| 1190 | + | |
| 1191 | + | |
| 1192 | + | |
| 1193 | + | |
| 1194 | + | |
| 1195 | + | |
| 1196 | + | |
| 1197 | + | |
1177 | 1198 | | |
1178 | 1199 | | |
1179 | 1200 | | |
| |||
0 commit comments