mirror of
https://github.com/PR0M3TH3AN/bitvid.git
synced 2026-11-06 21:02:28 +00:00
Preserve cached view totals when hydration fails
This commit is contained in:
1 parent
9d0aea45e7
commit
6e2db7a57f
1 file changed
+13
-2
+13
-2
@@ -49,7 +49,7 @@ restoreCacheSnapshot();
|
|||||||
* @property {number} total
|
* @property {number} total
|
||||||
* @property {Map<string, number>} dedupeBuckets
|
* @property {Map<string, number>} dedupeBuckets
|
||||||
* @property {number} lastSyncedAt
|
* @property {number} lastSyncedAt
|
||||||
* @property {"idle"|"hydrating"|"live"} status
|
* @property {"idle"|"hydrating"|"live"|"stale"} status
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -482,7 +482,8 @@ async function hydratePointer(key, listeners) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
let mutated = false;
|
let mutated = false;
|
||||||
if (Array.isArray(listResult)) {
|
const hasListEvents = Array.isArray(listResult) && listResult.length > 0;
|
||||||
|
if (hasListEvents) {
|
||||||
for (const event of listResult) {
|
for (const event of listResult) {
|
||||||
mutated = applyEventToState(key, event) || mutated;
|
mutated = applyEventToState(key, event) || mutated;
|
||||||
}
|
}
|
||||||
@@ -502,6 +503,13 @@ async function hydratePointer(key, listeners) {
|
|||||||
mutated = true;
|
mutated = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (!hasListEvents && bestCount === null) {
|
||||||
|
const state = ensurePointerState(key);
|
||||||
|
state.status = "stale";
|
||||||
|
schedulePersist();
|
||||||
|
notifyHandlers(key);
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (mutated) {
|
if (mutated) {
|
||||||
schedulePersist();
|
schedulePersist();
|
||||||
notifyHandlers(key);
|
notifyHandlers(key);
|
||||||
@@ -518,8 +526,11 @@ function ensureHydration(key, listeners) {
|
|||||||
if (!listeners.hydrationPromise) {
|
if (!listeners.hydrationPromise) {
|
||||||
listeners.hydrationPromise = hydratePointer(key, listeners).finally(() => {
|
listeners.hydrationPromise = hydratePointer(key, listeners).finally(() => {
|
||||||
listeners.hydrationPromise = null;
|
listeners.hydrationPromise = null;
|
||||||
|
const state = ensurePointerState(key);
|
||||||
if (listeners.liveUnsub) {
|
if (listeners.liveUnsub) {
|
||||||
setPointerStatus(key, "live");
|
setPointerStatus(key, "live");
|
||||||
|
} else if (state.status === "stale") {
|
||||||
|
setPointerStatus(key, "stale");
|
||||||
} else {
|
} else {
|
||||||
setPointerStatus(key, "idle");
|
setPointerStatus(key, "idle");
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user