1
0
Fork 0
forked from 0x2E/fusion

refactor: replace invalidateAll with invalidate for more granular cache control (#111)

This commit is contained in:
Yuan 2025-03-24 20:02:54 +08:00 committed by GitHub
parent 78e4666be3
commit 6ee9d9c110
Signed by: github
GPG key ID: B5690EEEBB952194
14 changed files with 35 additions and 23 deletions

View file

@ -1,5 +1,4 @@
<script lang="ts">
import { invalidateAll } from '$app/navigation';
import { refreshFeeds } from '$lib/api/feed';
import type { Feed } from '$lib/api/model';
import { t } from '$lib/i18n';
@ -21,14 +20,12 @@
}
toast.promise(refreshFeeds({ id: feed?.id, all: all }), {
success: () => {
invalidateAll();
if (all) {
return t('feed.refresh.all.run_in_background');
}
return t('state.success');
},
error: (e) => {
invalidateAll();
console.log(e);
return String(e);
}

View file

@ -1,5 +1,6 @@
<script lang="ts">
import { invalidateAll } from '$app/navigation';
import { invalidate } from '$app/navigation';
import { page } from '$app/state';
import { updateBookmark } from '$lib/api/item';
import type { Item } from '$lib/api/model';
import { t } from '$lib/i18n';
@ -16,7 +17,7 @@
e.preventDefault();
try {
await updateBookmark(data.id, !data.bookmark);
invalidateAll();
invalidate('page:' + page.url.pathname);
} catch (e) {
toast.error((e as Error).message);
}

View file

@ -1,5 +1,6 @@
<script lang="ts">
import { invalidateAll } from '$app/navigation';
import { invalidate } from '$app/navigation';
import { page } from '$app/state';
import { updateUnread } from '$lib/api/item';
import type { Item } from '$lib/api/model';
import { t } from '$lib/i18n';
@ -27,7 +28,7 @@
const ids = props.items.map((v) => v.id);
await updateUnread(ids, false);
toast.success(t('state.success'));
invalidateAll();
invalidate('page:' + page.url.pathname);
} catch (e) {
toast.error((e as Error).message);
}

View file

@ -1,5 +1,6 @@
<script lang="ts">
import { invalidateAll } from '$app/navigation';
import { invalidate } from '$app/navigation';
import { page } from '$app/state';
import { updateUnread } from '$lib/api/item';
import type { Item } from '$lib/api/model';
import { t } from '$lib/i18n';
@ -16,7 +17,7 @@
e.preventDefault();
try {
await updateUnread([data.id], !data.unread);
invalidateAll();
invalidate('page:' + page.url.pathname);
} catch (e) {
toast.error((e as Error).message);
}

View file

@ -39,7 +39,7 @@
filter.page = pageNumber;
const url = page.url;
applyFilterToURL(url, filter);
await goto(url, { invalidateAll: true });
await goto(url, { invalidate: ['page:' + page.url.pathname] });
}
</script>

View file

@ -2,7 +2,9 @@ import { listItems, parseURLtoFilter } from '$lib/api/item';
import { fullItemFilter } from '$lib/state.svelte';
import type { PageLoad } from './$types';
export const load: PageLoad = async ({ url }) => {
export const load: PageLoad = async ({ depends, url }) => {
depends(`page:${url.pathname}`);
const filter = parseURLtoFilter(url.searchParams, {
unread: true,
bookmark: undefined

View file

@ -2,7 +2,9 @@ import { listItems, parseURLtoFilter } from '$lib/api/item';
import { fullItemFilter } from '$lib/state.svelte';
import type { PageLoad } from './$types';
export const load: PageLoad = async ({ url }) => {
export const load: PageLoad = async ({ url, depends }) => {
depends(`page:${url.pathname}`);
const filter = parseURLtoFilter(url.searchParams, {
unread: undefined,
bookmark: undefined

View file

@ -2,7 +2,9 @@ import { listItems, parseURLtoFilter } from '$lib/api/item';
import { fullItemFilter } from '$lib/state.svelte';
import type { PageLoad } from './$types';
export const load: PageLoad = async ({ url }) => {
export const load: PageLoad = async ({ url, depends }) => {
depends(`page:${url.pathname}`);
const filter = parseURLtoFilter(url.searchParams, {
unread: undefined,
bookmark: true

View file

@ -5,7 +5,9 @@ import type { PageLoad } from './$types';
export const prerender = false;
export const load: PageLoad = async ({ url, params }) => {
export const load: PageLoad = async ({ depends, url, params }) => {
depends(`page:${url.pathname}`);
const id = parseInt(params.id);
const feed = getFeed(id);
const filter = parseURLtoFilter(url.searchParams, {

View file

@ -1,5 +1,6 @@
<script lang="ts">
import { goto, invalidateAll } from '$app/navigation';
import { goto, invalidate, invalidateAll } from '$app/navigation';
import { page } from '$app/state';
import { deleteFeed, updateFeed, type FeedUpdateForm } from '$lib/api/feed';
import type { Feed } from '$lib/api/model';
import { t } from '$lib/i18n';
@ -32,10 +33,10 @@
suspended: !feed.suspended
});
toast.success(t('state.success'));
invalidate('page:' + page.url.pathname);
} catch (e) {
toast.error((e as Error).message);
}
invalidateAll();
}
async function handleDelete() {
@ -47,7 +48,6 @@
} catch (e) {
toast.error((e as Error).message);
}
invalidateAll();
}
async function handleUpdate(e: Event) {
@ -55,12 +55,11 @@
toast.promise(updateFeed(feed.id, settingsForm), {
loading: 'Updating',
success: () => {
invalidateAll();
invalidate('page:' + page.url.pathname);
settingsModal?.close();
return t('state.success');
},
error: (e) => {
invalidateAll();
return (e as Error).message;
}
});

View file

@ -4,7 +4,9 @@ import type { PageLoad } from './$types';
export const prerender = false;
export const load: PageLoad = ({ params }) => {
export const load: PageLoad = ({ depends, url, params }) => {
depends(`page:${url.pathname}`);
const id = parseInt(params.id);
if (id < 1) {
error(404, 'wrong id');

View file

@ -1,5 +1,6 @@
<script lang="ts">
import { goto } from '$app/navigation';
import { page } from '$app/state';
import { listItems } from '$lib/api/item';
import type { Item } from '$lib/api/model';
import { defaultPageSize } from '$lib/consts';
@ -76,7 +77,9 @@
currentItemIndex = indexBackup;
return;
}
goto('/items/' + next.id, { invalidateAll: true });
goto('/items/' + next.id, {
invalidate: ['page:' + page.url.pathname]
});
}
</script>

View file

@ -18,7 +18,7 @@
applyFilterToURL(url, filterForm);
console.log(url.toString());
goto(url, {
invalidate: ['page:search']
invalidate: ['page:' + page.url.pathname]
});
}
</script>

View file

@ -3,7 +3,7 @@ import { fullItemFilter } from '$lib/state.svelte';
import type { PageLoad } from './$types';
export const load: PageLoad = async ({ url, depends }) => {
depends('page:search');
depends(`page:${url.pathname}`);
const filter = parseURLtoFilter(url.searchParams);
Object.assign(fullItemFilter, filter);