fix: update cache correctly

This commit is contained in:
Shusui MOYATANI
2023-12-25 11:32:43 +09:00
parent ea7f8354fa
commit 9fd8a34602

View File

@@ -22,7 +22,7 @@ export const latestEventQuery =
}); });
task.onUpdate((events) => { task.onUpdate((events) => {
const latest = pickLatestEvent(events); const latest = pickLatestEvent(events);
queryClient.setQueriesData<NostrEvent>({ queryKey, stale: true }, (prev) => { queryClient.setQueriesData<NostrEvent>({ queryKey }, (prev) => {
if (latest != null && (prev == null || compareEvents(latest, prev) >= 0)) { if (latest != null && (prev == null || compareEvents(latest, prev) >= 0)) {
return latest; return latest;
} }
@@ -47,7 +47,7 @@ export const eventsQuery =
const promise = task.toUpdatePromise().catch(() => []); const promise = task.toUpdatePromise().catch(() => []);
task.onUpdate((events) => { task.onUpdate((events) => {
// TODO consider kind:5 deletion // TODO consider kind:5 deletion
queryClient.setQueriesData<NostrEvent[]>({ queryKey, stale: true }, (prev) => { queryClient.setQueriesData<NostrEvent[]>({ queryKey }, (prev) => {
if (prev == null) return events; if (prev == null) return events;
const deduped = uniqBy([...prev, ...events], (e) => e.id); const deduped = uniqBy([...prev, ...events], (e) => e.id);
return sortEvents(deduped); return sortEvents(deduped);