mirror of
https://seed.radicle.dev/rad:z4V1sjrXqjvFdnCUbxPFqd5p4DtH5.git
synced 2026-11-29 10:10:30 +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:
@@ -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