From 5eeb763c0c830be4b2a44c6fda40e430458f9dcf Mon Sep 17 00:00:00 2001 From: Danny89530 Date: Sun, 29 Mar 2026 09:48:54 +0200 Subject: [PATCH] perf: replace per-script PocketBase logo lookups with local cache check in getAllDownloadedScripts (#526) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit getAllDownloadedScripts called localScriptsService.getScriptBySlug() for every .sh file found on disk in order to resolve the logo URL. That method queries PocketBase individually for each slug, turning a simple directory scan into N sequential HTTP round-trips (N ≈ 535 on a typical install). Measured impact on a populated instance: Before: getAllDownloadedScripts → ~77 s After: getAllDownloadedScripts → ~0.1 s Because the build step (cache-logos.ts) and the hourly auto-sync both already download every logo to public/logos/{slug}.webp, the logo is virtually always present on disk. Replace the remote lookup with a lightweight fs.access() check against the local cache; no network call is made and no logo data is lost. Co-authored-by: Daloiso Danilo Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- src/server/lib/scripts.ts | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/server/lib/scripts.ts b/src/server/lib/scripts.ts index 6cc408c..c0df301 100644 --- a/src/server/lib/scripts.ts +++ b/src/server/lib/scripts.ts @@ -1,8 +1,7 @@ -import { readdir, stat, readFile } from 'fs/promises'; +import { readdir, stat, readFile, access } from 'fs/promises'; import { join, resolve, extname } from 'path'; import { env } from '~/env.js'; import { spawn, type ChildProcess } from 'child_process'; -import { localScriptsService } from '~/server/services/localScripts'; export interface ScriptInfo { name: string; @@ -130,13 +129,14 @@ export class ScriptManager { // Extract slug from filename (remove .sh extension) const slug = file.replace(/\.sh$/, ''); - // Try to get logo from JSON data + // Try to get logo from local cache (avoids per-script HTTP calls to PocketBase) let logo: string | undefined; try { - const scriptData = await localScriptsService.getScriptBySlug(slug); - logo = scriptData?.logo ?? undefined; + const logoPath = join(process.cwd(), 'public', 'logos', `${slug}.webp`); + await access(logoPath); + logo = `/logos/${slug}.webp`; } catch { - // JSON file might not exist, that's okay + // Logo not cached locally, that's okay } scripts.push({ @@ -217,13 +217,14 @@ export class ScriptManager { // Extract slug from filename (remove .sh extension) const slug = file.replace(/\.sh$/, ''); - // Try to get logo from JSON data + // Try to get logo from local cache (avoids per-script HTTP calls to PocketBase) let logo: string | undefined; try { - const scriptData = await localScriptsService.getScriptBySlug(slug); - logo = scriptData?.logo ?? undefined; + const logoPath = join(process.cwd(), 'public', 'logos', `${slug}.webp`); + await access(logoPath); + logo = `/logos/${slug}.webp`; } catch { - // JSON file might not exist, that's okay + // Logo not cached locally, that's okay } scripts.push({