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

View file

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

View file

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

View file

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

View file

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

View file

@ -2,7 +2,9 @@ import { listItems, parseURLtoFilter } from '$lib/api/item';
import { fullItemFilter } from '$lib/state.svelte'; import { fullItemFilter } from '$lib/state.svelte';
import type { PageLoad } from './$types'; 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, { const filter = parseURLtoFilter(url.searchParams, {
unread: true, unread: true,
bookmark: undefined bookmark: undefined

View file

@ -2,7 +2,9 @@ import { listItems, parseURLtoFilter } from '$lib/api/item';
import { fullItemFilter } from '$lib/state.svelte'; import { fullItemFilter } from '$lib/state.svelte';
import type { PageLoad } from './$types'; 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, { const filter = parseURLtoFilter(url.searchParams, {
unread: undefined, unread: undefined,
bookmark: undefined bookmark: undefined

View file

@ -2,7 +2,9 @@ import { listItems, parseURLtoFilter } from '$lib/api/item';
import { fullItemFilter } from '$lib/state.svelte'; import { fullItemFilter } from '$lib/state.svelte';
import type { PageLoad } from './$types'; 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, { const filter = parseURLtoFilter(url.searchParams, {
unread: undefined, unread: undefined,
bookmark: true bookmark: true

View file

@ -5,7 +5,9 @@ import type { PageLoad } from './$types';
export const prerender = false; 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 id = parseInt(params.id);
const feed = getFeed(id); const feed = getFeed(id);
const filter = parseURLtoFilter(url.searchParams, { const filter = parseURLtoFilter(url.searchParams, {

View file

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

View file

@ -4,7 +4,9 @@ import type { PageLoad } from './$types';
export const prerender = false; 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); const id = parseInt(params.id);
if (id < 1) { if (id < 1) {
error(404, 'wrong id'); error(404, 'wrong id');

View file

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

View file

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

View file

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