mirror of
https://seed.radicle.dev/rad:z4V1sjrXqjvFdnCUbxPFqd5p4DtH5.git
synced 2026-11-21 14:20:42 +08:00
desktop: Drop hover caches when data changes
Hover cards, references and mention candidates keep their own short-lived caches, which went on showing an issue's or patch's old state for up to a minute after the views around them had updated.
This commit is contained in:
@@ -16,6 +16,7 @@ import type { RepoSummary } from "@bindings/repo/RepoSummary";
|
||||
import type { TreePath } from "@bindings/repo/TreePath";
|
||||
|
||||
import { cached } from "@radicle-gui/ui/lib/cached";
|
||||
import { invalidate } from "@radicle-gui/ui/lib/query.svelte";
|
||||
import * as tauri from "@tauri-apps/api/core";
|
||||
|
||||
import { labs } from "@app/lib/labs";
|
||||
@@ -35,8 +36,10 @@ export async function invoke<T = null>(
|
||||
return result;
|
||||
} finally {
|
||||
// Also after a failure: a command can fail after writing part of a change.
|
||||
for (const queryKey of writtenKeys(cmd, args, result)) {
|
||||
void queryClient.invalidateQueries({ queryKey });
|
||||
const written = writtenKeys(cmd, args, result);
|
||||
if (written.length > 0) clearEntityCaches();
|
||||
for (const queryKey of written) {
|
||||
void invalidate(queryClient, { queryKey });
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -310,6 +313,20 @@ export const cachedReleaseById = cached(
|
||||
missTtl,
|
||||
);
|
||||
|
||||
// The caches above hold data that changes: references, hover cards and
|
||||
// mention candidates. They are dropped whenever data changes, so that they
|
||||
// show the same as the views around them.
|
||||
export function clearEntityCaches(): void {
|
||||
cachedListIssueCandidates.clear();
|
||||
cachedListPatchCandidates.clear();
|
||||
cachedListReleaseCandidates.clear();
|
||||
cachedRepoById.clear();
|
||||
cachedIssueById.clear();
|
||||
cachedPatchById.clear();
|
||||
cachedReleaseById.clear();
|
||||
cachedRepoSplitTreePath.clear();
|
||||
}
|
||||
|
||||
async function repoCommit(rid: string, sha: string): Promise<Commit | null> {
|
||||
return withTestBackend(tauri.invoke, "repo_commit", { rid, sha });
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ import { listen } from "@tauri-apps/api/event";
|
||||
import once from "lodash/once";
|
||||
import { get } from "svelte/store";
|
||||
|
||||
import { invoke } from "@app/lib/invoke";
|
||||
import { clearEntityCaches, invoke } from "@app/lib/invoke";
|
||||
import { queryClient } from "@app/lib/query";
|
||||
import { fetchingRepos } from "@app/lib/seedRepo";
|
||||
|
||||
@@ -26,6 +26,7 @@ export function batch(delay: number, jobs: boolean): (affected: Key[]) => void {
|
||||
flush = undefined;
|
||||
const queryKeys = [...pending.values()];
|
||||
pending.clear();
|
||||
if (!jobs) clearEntityCaches();
|
||||
for (const queryKey of queryKeys) {
|
||||
void queryClient.invalidateQueries({
|
||||
queryKey,
|
||||
@@ -105,6 +106,7 @@ export const createEventEmittersOnce = once(async (): Promise<UnlistenFn> => {
|
||||
}),
|
||||
// The backend may have missed events while it wasn't subscribed.
|
||||
listen("ref_resync", () => {
|
||||
clearEntityCaches();
|
||||
void queryClient.invalidateQueries();
|
||||
}),
|
||||
]);
|
||||
@@ -114,6 +116,7 @@ export const createEventEmittersOnce = once(async (): Promise<UnlistenFn> => {
|
||||
// have changed.
|
||||
const onFocus = () => {
|
||||
if (!get(nodeEvents)) {
|
||||
clearEntityCaches();
|
||||
void queryClient.invalidateQueries({
|
||||
predicate: query => !isJobs(query.queryKey as Key),
|
||||
});
|
||||
|
||||
@@ -5,11 +5,12 @@ import { afterEach, beforeEach, describe, expect, test, vi } from "vitest";
|
||||
|
||||
import { batch, onRefUpdate } from "@app/lib/startup.svelte";
|
||||
|
||||
const { invalidateQueries } = vi.hoisted(() => ({
|
||||
const { invalidateQueries, clearEntityCaches } = vi.hoisted(() => ({
|
||||
invalidateQueries: vi.fn(),
|
||||
clearEntityCaches: vi.fn(),
|
||||
}));
|
||||
vi.mock("@app/lib/query", () => ({ queryClient: { invalidateQueries } }));
|
||||
vi.mock("@app/lib/invoke", () => ({ invoke: vi.fn() }));
|
||||
vi.mock("@app/lib/invoke", () => ({ clearEntityCaches, invoke: vi.fn() }));
|
||||
vi.mock("@tauri-apps/api/event", () => ({ listen: vi.fn() }));
|
||||
vi.mock("@app/lib/seedRepo", async () => {
|
||||
const { writable } = await import("svelte/store");
|
||||
@@ -41,6 +42,7 @@ beforeEach(() => {
|
||||
afterEach(() => {
|
||||
vi.useRealTimers();
|
||||
invalidateQueries.mockReset();
|
||||
clearEntityCaches.mockReset();
|
||||
});
|
||||
|
||||
describe("batch", () => {
|
||||
@@ -56,6 +58,7 @@ describe("batch", () => {
|
||||
keys.issues(rid),
|
||||
keys.patches(rid),
|
||||
]);
|
||||
expect(clearEntityCaches).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
test("leaves job lists under a repository key to their own batch", () => {
|
||||
@@ -77,6 +80,7 @@ describe("batch", () => {
|
||||
|
||||
const [call] = invalidateQueries.mock.calls;
|
||||
expect(covers(call, keys.jobs(rid))).toBe(true);
|
||||
expect(clearEntityCaches).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
test("an update naming no refs refreshes job lists in their own batch", () => {
|
||||
|
||||
Reference in New Issue
Block a user