mirror of
https://seed.radicle.dev/rad:z4V1sjrXqjvFdnCUbxPFqd5p4DtH5.git
synced 2026-11-21 14:20:42 +08:00
Add rebuild cache functionality to issue and patch listing
In case of an outdated cobs cache we display a banner on top of the patch or issue listing, to allow users to rebuild the cobs cache of a repo similar to running `rad patch cache` After rebuilding we fetch the issues or patches from the start. Small caveat with patches: The banner can only be shown after a user fetched all patches from the backend, so we are sure we tried to fetch all of them.
This commit is contained in:
@@ -3,7 +3,14 @@
|
||||
|
||||
interface Props {
|
||||
children: Snippet;
|
||||
variant: "primary" | "secondary" | "ghost" | "float" | "danger" | "success";
|
||||
variant:
|
||||
| "primary"
|
||||
| "secondary"
|
||||
| "ghost"
|
||||
| "float"
|
||||
| "danger"
|
||||
| "success"
|
||||
| "outline";
|
||||
hoverable?: boolean;
|
||||
onclick?: (e: MouseEvent) => void;
|
||||
stylePosition?: string;
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
import type { IssueStatus } from "@app/views/repo/router";
|
||||
import type { ProjectPayload } from "@bindings/repo/ProjectPayload";
|
||||
|
||||
export const issueCounts = $state<
|
||||
Record<IssueStatus, { sidebar: number | null; total: number | null }>
|
||||
>({
|
||||
all: { sidebar: null, total: null },
|
||||
open: { sidebar: null, total: null },
|
||||
closed: { sidebar: null, total: null },
|
||||
});
|
||||
|
||||
export function issueCountMismatch(status: IssueStatus) {
|
||||
return issueCounts[status].total !== issueCounts[status].sidebar;
|
||||
}
|
||||
|
||||
export function resetIssueCounts() {
|
||||
Object.values(issueCounts).forEach(count => {
|
||||
count.sidebar = null;
|
||||
count.total = null;
|
||||
});
|
||||
}
|
||||
|
||||
export function updateIssueCounts(
|
||||
itemCount: number,
|
||||
sidebarCount: ProjectPayload["meta"]["issues"] & { all: number },
|
||||
status: IssueStatus,
|
||||
) {
|
||||
issueCounts[status].total = itemCount;
|
||||
issueCounts[status].sidebar = sidebarCount[status];
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
import type { PatchStatus } from "@app/views/repo/router";
|
||||
import type { ProjectPayload } from "@bindings/repo/ProjectPayload";
|
||||
|
||||
import sum from "lodash/sum";
|
||||
|
||||
export const patchCounts = $state<
|
||||
Record<PatchStatus | "all", { sidebar: number | null; total: number | null }>
|
||||
>({
|
||||
draft: { sidebar: null, total: null },
|
||||
open: { sidebar: null, total: null },
|
||||
archived: { sidebar: null, total: null },
|
||||
merged: { sidebar: null, total: null },
|
||||
all: { sidebar: null, total: null },
|
||||
});
|
||||
|
||||
export function patchCountMismatch(status?: PatchStatus) {
|
||||
return (
|
||||
patchCounts[status || "all"].total !== patchCounts[status || "all"].sidebar
|
||||
);
|
||||
}
|
||||
|
||||
export function resetPatchCounts() {
|
||||
Object.values(patchCounts).forEach(count => {
|
||||
count.sidebar = null;
|
||||
count.total = null;
|
||||
});
|
||||
}
|
||||
|
||||
export function updatePatchCounts(
|
||||
itemCount: number,
|
||||
sidebarCount: ProjectPayload["meta"]["patches"],
|
||||
status?: PatchStatus,
|
||||
) {
|
||||
if (status) {
|
||||
patchCounts[status].total = itemCount;
|
||||
patchCounts[status].sidebar = sidebarCount[status];
|
||||
} else {
|
||||
patchCounts["all"].total = itemCount;
|
||||
patchCounts["all"].sidebar = sum(Object.values(sidebarCount));
|
||||
}
|
||||
}
|
||||
@@ -1,13 +1,21 @@
|
||||
<script lang="ts">
|
||||
import type { CacheEvent } from "@bindings/cob/CacheEvent";
|
||||
import type { Config } from "@bindings/config/Config";
|
||||
import type { Issue } from "@bindings/cob/issue/Issue";
|
||||
import type { IssueStatus } from "./router";
|
||||
import type { IssueStatus } from "@app/views/repo/router";
|
||||
import type { RepoInfo } from "@bindings/repo/RepoInfo";
|
||||
|
||||
import delay from "lodash/delay";
|
||||
import fuzzysort from "fuzzysort";
|
||||
import { Channel } from "@tauri-apps/api/core";
|
||||
|
||||
import * as router from "@app/lib/router";
|
||||
import { explorerUrl, modifierKey } from "@app/lib/utils";
|
||||
import { invoke } from "@app/lib/invoke";
|
||||
import {
|
||||
issueCountMismatch,
|
||||
resetIssueCounts,
|
||||
} from "@app/lib/issueCounts.svelte";
|
||||
|
||||
import Border from "@app/components/Border.svelte";
|
||||
import Button from "@app/components/Button.svelte";
|
||||
@@ -15,6 +23,7 @@
|
||||
import IssueTeaser from "@app/components/IssueTeaser.svelte";
|
||||
import IssuesSecondColumn from "@app/components/IssuesSecondColumn.svelte";
|
||||
import NodeBreadcrumb from "@app/components/NodeBreadcrumb.svelte";
|
||||
import Spinner from "@app/components/Spinner.svelte";
|
||||
import TextInput from "@app/components/TextInput.svelte";
|
||||
|
||||
import BreadcrumbCopyButton from "./BreadcrumbCopyButton.svelte";
|
||||
@@ -34,10 +43,33 @@
|
||||
let { notificationCount, repo, issues, config, status }: Props = $props();
|
||||
/* eslint-enable prefer-const */
|
||||
|
||||
let cacheState: CacheEvent | undefined = $state();
|
||||
|
||||
const project = $derived(repo.payloads["xyz.radicle.project"]!);
|
||||
|
||||
let searchInput = $state("");
|
||||
|
||||
async function rebuildIssueCache() {
|
||||
try {
|
||||
await invoke("rebuild_issue_cache", {
|
||||
rid: repo.rid,
|
||||
onEvent: new Channel<CacheEvent>(message => {
|
||||
cacheState = message;
|
||||
}),
|
||||
});
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
} finally {
|
||||
issues = await invoke<Issue[]>("list_issues", { rid: repo.rid, status });
|
||||
|
||||
resetIssueCounts();
|
||||
|
||||
delay(() => {
|
||||
cacheState = undefined;
|
||||
}, 1500);
|
||||
}
|
||||
}
|
||||
|
||||
$effect(() => {
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
|
||||
status;
|
||||
@@ -112,6 +144,40 @@
|
||||
{/snippet}
|
||||
|
||||
<div class="container">
|
||||
{#if issueCountMismatch(status)}
|
||||
<div style="margin-bottom: 1rem;">
|
||||
<Border
|
||||
styleOverflow="hidden"
|
||||
styleBackgroundColor="var(--color-fill-private)"
|
||||
stylePadding="0.25rem 0.5rem"
|
||||
styleGap="1rem"
|
||||
variant="outline">
|
||||
<div class="txt-overflow txt-small global-flex">
|
||||
<Icon name="warning" />
|
||||
<span class="txt-overflow">
|
||||
There’s a problem with your COB cache, so some issues may not be
|
||||
displayed. You can rebuild the cache to resolve this.
|
||||
</span>
|
||||
</div>
|
||||
<div style:margin-left="auto">
|
||||
<Button
|
||||
variant="ghost"
|
||||
onclick={rebuildIssueCache}
|
||||
disabled={cacheState !== undefined}>
|
||||
{#if cacheState?.event === "started" || cacheState?.event === "progress"}
|
||||
Rebuilding
|
||||
<Spinner />
|
||||
{:else if cacheState?.event === "finished"}
|
||||
Done
|
||||
<Icon name="checkmark" />
|
||||
{:else}
|
||||
Rebuild cache
|
||||
{/if}
|
||||
</Button>
|
||||
</div>
|
||||
</Border>
|
||||
</div>
|
||||
{/if}
|
||||
<div class="header">
|
||||
<div>Issues</div>
|
||||
<div class="global-flex" style:margin-left="auto" style:gap="0.75rem">
|
||||
|
||||
@@ -1,23 +1,33 @@
|
||||
<script lang="ts">
|
||||
import type { CacheEvent } from "@bindings/cob/CacheEvent";
|
||||
import type { Config } from "@bindings/config/Config";
|
||||
import type { PaginatedQuery } from "@bindings/cob/PaginatedQuery";
|
||||
import type { Patch } from "@bindings/cob/patch/Patch";
|
||||
import type { PatchStatus } from "./router";
|
||||
import type { PatchStatus } from "@app/views/repo/router";
|
||||
import type { RepoInfo } from "@bindings/repo/RepoInfo";
|
||||
|
||||
import delay from "lodash/delay";
|
||||
import fuzzysort from "fuzzysort";
|
||||
import { Channel } from "@tauri-apps/api/core";
|
||||
|
||||
import * as router from "@app/lib/router";
|
||||
import { DEFAULT_TAKE } from "./router";
|
||||
import { invoke } from "@app/lib/invoke";
|
||||
import { DEFAULT_TAKE } from "@app/views/repo/router";
|
||||
import { explorerUrl, modifierKey } from "@app/lib/utils";
|
||||
import { invoke } from "@app/lib/invoke";
|
||||
import {
|
||||
patchCountMismatch,
|
||||
resetPatchCounts,
|
||||
updatePatchCounts,
|
||||
} from "@app/lib/patchCounts.svelte";
|
||||
|
||||
import Border from "@app/components/Border.svelte";
|
||||
import Button from "@app/components/Button.svelte";
|
||||
import Icon from "@app/components/Icon.svelte";
|
||||
import NewPatchButton from "@app/components/NewPatchButton.svelte";
|
||||
import NodeBreadcrumb from "@app/components/NodeBreadcrumb.svelte";
|
||||
import PatchTeaser from "@app/components/PatchTeaser.svelte";
|
||||
import PatchesSecondColumn from "@app/components/PatchesSecondColumn.svelte";
|
||||
import Spinner from "@app/components/Spinner.svelte";
|
||||
import TextInput from "@app/components/TextInput.svelte";
|
||||
|
||||
import BreadcrumbCopyButton from "./BreadcrumbCopyButton.svelte";
|
||||
@@ -39,10 +49,25 @@
|
||||
let cursor = patches.cursor;
|
||||
let more = patches.more;
|
||||
|
||||
const project = $derived(repo.payloads["xyz.radicle.project"]!);
|
||||
|
||||
let cacheState: CacheEvent | undefined = $state();
|
||||
|
||||
$effect(() => {
|
||||
items = patches.content;
|
||||
cursor = patches.cursor;
|
||||
more = patches.more;
|
||||
// If the first page is not full, we know there are no more patches.
|
||||
if (patches.more === true && patches.content.length < DEFAULT_TAKE) {
|
||||
more = false;
|
||||
} else {
|
||||
more = patches.more;
|
||||
}
|
||||
});
|
||||
|
||||
$effect(() => {
|
||||
if (more === false) {
|
||||
updatePatchCounts(items.length, project.meta.patches, status);
|
||||
}
|
||||
});
|
||||
|
||||
$effect(() => {
|
||||
@@ -52,6 +77,36 @@
|
||||
searchInput = "";
|
||||
});
|
||||
|
||||
async function rebuildPatchCache() {
|
||||
try {
|
||||
await invoke("rebuild_patch_cache", {
|
||||
rid: repo.rid,
|
||||
onEvent: new Channel<CacheEvent>(message => {
|
||||
cacheState = message;
|
||||
}),
|
||||
});
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
} finally {
|
||||
const p = await invoke<PaginatedQuery<Patch[]>>("list_patches", {
|
||||
rid: repo.rid,
|
||||
skip: 0,
|
||||
status,
|
||||
take: DEFAULT_TAKE,
|
||||
});
|
||||
|
||||
items = p.content;
|
||||
cursor = p.cursor;
|
||||
more = p.more;
|
||||
|
||||
resetPatchCounts();
|
||||
|
||||
delay(() => {
|
||||
cacheState = undefined;
|
||||
}, 1500);
|
||||
}
|
||||
}
|
||||
|
||||
async function loadMoreContent(all: boolean = false) {
|
||||
if (more) {
|
||||
const p = await invoke<PaginatedQuery<Patch[]>>("list_patches", {
|
||||
@@ -69,11 +124,18 @@
|
||||
} else {
|
||||
items = [...items, ...p.content];
|
||||
}
|
||||
|
||||
// If the newly fetched patches are empty, there is no more to fetch.
|
||||
if (p.content.length === 0) {
|
||||
more = false;
|
||||
}
|
||||
|
||||
if (more === false) {
|
||||
updatePatchCounts(items.length, project.meta.patches, status);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const project = $derived(repo.payloads["xyz.radicle.project"]!);
|
||||
|
||||
let loading: boolean = $state(false);
|
||||
let searchInput = $state("");
|
||||
|
||||
@@ -146,6 +208,40 @@
|
||||
{/snippet}
|
||||
|
||||
<div class="container">
|
||||
{#if patchCountMismatch(status)}
|
||||
<div style="margin-bottom: 1rem;">
|
||||
<Border
|
||||
styleOverflow="hidden"
|
||||
styleBackgroundColor="var(--color-fill-private)"
|
||||
stylePadding="0.25rem 0.5rem"
|
||||
styleGap="1rem"
|
||||
variant="outline">
|
||||
<div class="txt-overflow txt-small global-flex">
|
||||
<Icon name="warning" />
|
||||
<span class="txt-overflow">
|
||||
There’s a problem with your COB cache, so some patches may not be
|
||||
displayed. You can rebuild the cache to resolve this.
|
||||
</span>
|
||||
</div>
|
||||
<div style:margin-left="auto">
|
||||
<Button
|
||||
variant="ghost"
|
||||
onclick={rebuildPatchCache}
|
||||
disabled={cacheState !== undefined}>
|
||||
{#if cacheState?.event === "started" || cacheState?.event === "progress"}
|
||||
Rebuilding
|
||||
<Spinner />
|
||||
{:else if cacheState?.event === "finished"}
|
||||
Done
|
||||
<Icon name="checkmark" />
|
||||
{:else}
|
||||
Rebuild cache
|
||||
{/if}
|
||||
</Button>
|
||||
</div>
|
||||
</Border>
|
||||
</div>
|
||||
{/if}
|
||||
<div class="header">
|
||||
Patches
|
||||
|
||||
|
||||
Reference in New Issue
Block a user