perf: replace per-script PocketBase logo lookups with local cache check in getAllDownloadedScripts (#526)

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 <danilo.daloiso@intellitronika.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
Danny89530
2026-03-29 09:48:54 +02:00
committed by GitHub
parent 64089ed88b
commit 5eeb763c0c

View File

@@ -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({