warm up the cache on mount

This commit is contained in:
Nikita Galaiko 2023-03-28 16:02:10 +02:00
parent 6b147d4d25
commit 20c03d6e96
2 changed files with 13 additions and 2 deletions

View File

@ -62,7 +62,7 @@ export const listFiles = async (params: {
const sessionsCache: Record<string, Promise<Session[]>> = {};
const list = async (params: { projectId: string; earliestTimestampMs?: number }) => {
export const list = async (params: { projectId: string; earliestTimestampMs?: number }) => {
if (params.projectId in sessionsCache) {
return sessionsCache[params.projectId].then((sessions) =>
sessions.filter((s) =>

View File

@ -4,10 +4,11 @@
import { Toaster } from 'svelte-french-toast';
import type { LayoutData } from './$types';
import { BackForwardButtons } from '$lib/components';
import { setContext } from 'svelte';
import { onMount, setContext } from 'svelte';
import { writable } from 'svelte/store';
import Breadcrumbs from '$lib/components/Breadcrumbs.svelte';
import CommandPalette from '$lib/components/CommandPalette';
import { list as listSessions, listFiles } from '$lib/sessions';
export let data: LayoutData;
const { user, posthog, projects } = data;
@ -16,6 +17,16 @@
setContext('session', writable(null));
setContext('projects', projects);
onMount(() =>
// warm up the cache
$projects.forEach(async (project) => {
const sessions = await listSessions({ projectId: project.id });
sessions.forEach(async (session) => {
listFiles({ projectId: project.id, sessionId: session.id });
});
})
);
user.subscribe(posthog.identify);
</script>