From ec7616c7a1a0a22d825676f79d24ec745d3f2d25 Mon Sep 17 00:00:00 2001 From: Sam Chau Date: Sun, 9 Nov 2025 07:41:20 +1100 Subject: [PATCH] fix: remove scoring streaming --- deno.json | 3 +- .../pcd/queries/qualityProfiles/list.ts | 6 +- .../pcd/queries/qualityProfiles/scoring.ts | 8 +- .../[databaseId]/[id]/scoring/+page.server.ts | 26 +--- .../[databaseId]/[id]/scoring/+page.svelte | 121 ++++++------------ 5 files changed, 56 insertions(+), 108 deletions(-) diff --git a/deno.json b/deno.json index e0a35de..691bcfb 100644 --- a/deno.json +++ b/deno.json @@ -22,9 +22,8 @@ }, "tasks": { "dev": "APP_BASE_PATH=./dist/dev deno run -A npm:vite dev", - "build": "APP_BASE_PATH=./dist/build deno run -A npm:vite build", + "build": "APP_BASE_PATH=./dist/build deno run -A npm:vite build && deno compile --no-check --allow-net --allow-read --allow-write --allow-env --allow-ffi --allow-run --target x86_64-unknown-linux-gnu --output dist/build/profilarr dist/build/mod.ts", "preview": "APP_BASE_PATH=./dist/data ./dist/build/profilarr", - "compile": "deno compile --no-check --allow-net --allow-read --allow-write --allow-env --allow-ffi --allow-run --target x86_64-unknown-linux-gnu --output dist/build/profilarr dist/build/mod.ts", "format": "prettier --write .", "lint": "prettier --check . && eslint .", "test": "APP_BASE_PATH=./dist/test deno test src/tests --allow-read --allow-write --allow-env", diff --git a/src/lib/server/pcd/queries/qualityProfiles/list.ts b/src/lib/server/pcd/queries/qualityProfiles/list.ts index 4e3b43b..eef747d 100644 --- a/src/lib/server/pcd/queries/qualityProfiles/list.ts +++ b/src/lib/server/pcd/queries/qualityProfiles/list.ts @@ -45,7 +45,8 @@ export async function list(cache: PCDCache): Promise { 't.created_at as tag_created_at' ]) .where('qpt.quality_profile_id', 'in', profileIds) - .orderBy(['qpt.quality_profile_id', 't.name']) + .orderBy('qpt.quality_profile_id') + .orderBy('t.name') .execute(); // 3. Get custom format counts grouped by arr_type @@ -72,7 +73,8 @@ export async function list(cache: PCDCache): Promise { 'qg.name as group_name' ]) .where('qpq.quality_profile_id', 'in', profileIds) - .orderBy(['qpq.quality_profile_id', 'qpq.position']) + .orderBy('qpq.quality_profile_id') + .orderBy('qpq.position') .execute(); // 5. Get languages for all profiles diff --git a/src/lib/server/pcd/queries/qualityProfiles/scoring.ts b/src/lib/server/pcd/queries/qualityProfiles/scoring.ts index ab2c08e..10ebbca 100644 --- a/src/lib/server/pcd/queries/qualityProfiles/scoring.ts +++ b/src/lib/server/pcd/queries/qualityProfiles/scoring.ts @@ -4,12 +4,14 @@ import type { PCDCache } from '../../cache.ts'; import type { QualityProfileScoring } from '../../types.ts'; +import { logger } from '$logger/logger.ts'; /** * Get quality profile scoring data * Returns all custom formats with their scores per arr type */ export async function scoring(cache: PCDCache, databaseId: number, profileId: number): Promise { + await logger.debug('scoring query called', { source: 'scoring', meta: { databaseId, profileId } }); const db = cache.kb; // 1. Get profile settings @@ -88,7 +90,7 @@ export async function scoring(cache: PCDCache, databaseId: number, profileId: nu }; }); - return { + const result = { databaseId, arrTypes, customFormats: customFormatScoring, @@ -96,4 +98,8 @@ export async function scoring(cache: PCDCache, databaseId: number, profileId: nu upgrade_until_score: profile.upgrade_until_score, upgrade_score_increment: profile.upgrade_score_increment }; + + await logger.debug('scoring query completed', { source: 'scoring', meta: { customFormatCount: customFormatScoring.length } }); + + return result; } diff --git a/src/routes/quality-profiles/[databaseId]/[id]/scoring/+page.server.ts b/src/routes/quality-profiles/[databaseId]/[id]/scoring/+page.server.ts index d140020..ddb8b4e 100644 --- a/src/routes/quality-profiles/[databaseId]/[id]/scoring/+page.server.ts +++ b/src/routes/quality-profiles/[databaseId]/[id]/scoring/+page.server.ts @@ -3,7 +3,7 @@ import type { ServerLoad } from '@sveltejs/kit'; import { pcdManager } from '$pcd/pcd.ts'; import * as qualityProfileQueries from '$pcd/queries/qualityProfiles/index.ts'; -export const load: ServerLoad = async ({ params, isDataRequest }) => { +export const load: ServerLoad = async ({ params }) => { const { databaseId, id } = params; // Validate params exist @@ -29,23 +29,9 @@ export const load: ServerLoad = async ({ params, isDataRequest }) => { throw error(500, 'Database cache not available'); } - // Always return synchronous data at top level, stream the heavy data - if (isDataRequest) { - // Client-side navigation - stream the data - return { - loaded: true, // Synchronous data to enable instant navigation - streamed: { - scoring: qualityProfileQueries.scoring(cache, currentDatabaseId, profileId) - } - }; - } else { - // Initial page load - await the data for SEO - const scoringData = await qualityProfileQueries.scoring(cache, currentDatabaseId, profileId); - return { - loaded: true, - streamed: { - scoring: Promise.resolve(scoringData) - } - }; - } + const scoringData = await qualityProfileQueries.scoring(cache, currentDatabaseId, profileId); + + return { + scoring: scoringData + }; }; diff --git a/src/routes/quality-profiles/[databaseId]/[id]/scoring/+page.svelte b/src/routes/quality-profiles/[databaseId]/[id]/scoring/+page.svelte index bd5687b..c04201a 100644 --- a/src/routes/quality-profiles/[databaseId]/[id]/scoring/+page.svelte +++ b/src/routes/quality-profiles/[databaseId]/[id]/scoring/+page.svelte @@ -30,7 +30,6 @@ let upgradeScoreIncrement = 0; let customFormatScores: Record> = {}; let customFormatEnabled: Record> = {}; - let scoringData: any = null; // Track initial values let initialMinimumScore = 0; @@ -306,25 +305,51 @@ return arrTypeColors[arrType] || '#3b82f6'; // default to blue } + $: scoring = data.scoring; + + // Compute filtered and sorted formats + $: searchQuery = ($searchStore.query ?? '').trim().toLowerCase(); + $: filteredCustomFormats = scoring?.customFormats.filter((format) => { + if (searchQuery && !format.name?.toLowerCase().includes(searchQuery)) { + return false; + } + if (hideUnscoredFormats) { + const hasAnyScore = scoring.arrTypes.some((arrType) => format.scores[arrType] !== null); + if (!hasAnyScore) return false; + } + return true; + }) || []; + + $: sortedCustomFormats = sortFormats(filteredCustomFormats, state, sortState); + $: groupedFormats = groupFormats(sortedCustomFormats, selectedGroups); + + // Apply default sort + $: if (scoring && !sortState) { + const defaultSortKey = (scoring.arrTypes.includes('radarr') ? 'radarr' : scoring.arrTypes[0]) as SortKey; + if (defaultSortKey) { + sortState = { key: defaultSortKey, direction: 'desc' }; + } + } + // Reactive state - initialize from data - $: if (scoringData) { - minimumScore = scoringData.minimum_custom_format_score; - upgradeUntilScore = scoringData.upgrade_until_score; - upgradeScoreIncrement = scoringData.upgrade_score_increment; + $: if (scoring) { + minimumScore = scoring.minimum_custom_format_score; + upgradeUntilScore = scoring.upgrade_until_score; + upgradeScoreIncrement = scoring.upgrade_score_increment; // Save initial values - initialMinimumScore = scoringData.minimum_custom_format_score; - initialUpgradeUntilScore = scoringData.upgrade_until_score; - initialUpgradeScoreIncrement = scoringData.upgrade_score_increment; + initialMinimumScore = scoring.minimum_custom_format_score; + initialUpgradeUntilScore = scoring.upgrade_until_score; + initialUpgradeScoreIncrement = scoring.upgrade_score_increment; // Initialize scores and enabled state from data const newScores: Record> = {}; const newEnabled: Record> = {}; - scoringData.customFormats.forEach((cf: any) => { + scoring.customFormats.forEach((cf: any) => { newScores[cf.id] = { ...cf.scores }; newEnabled[cf.id] = {}; - scoringData.arrTypes.forEach((arrType: string) => { + scoring.arrTypes.forEach((arrType: string) => { newEnabled[cf.id][arrType] = cf.scores[arrType] !== null; }); }); @@ -437,78 +462,8 @@ -{#await data.streamed.scoring} - -
- -
- {#each [1, 2, 3] as _} -
-
-
-
-
- {/each} -
- - -
-
-
-
-
-
-
- - -
-
-
-
-
-
-
-
-
-
- {#each [1, 2, 3, 4, 5] as _} -
-
-
-
-
- {/each} -
-
-
-
-{:then scoring} - {@const _ = (scoringData = scoring, null)} - {@const searchQuery = ($searchStore.query ?? '').trim().toLowerCase()} - {@const filteredCustomFormats = scoring.customFormats.filter((format) => { - // Filter by search - if (searchQuery && !format.name?.toLowerCase().includes(searchQuery)) { - return false; - } - - // Filter unscored formats if option is enabled - if (hideUnscoredFormats) { - const hasAnyScore = scoring.arrTypes.some((arrType) => format.scores[arrType] !== null); - if (!hasAnyScore) return false; - } - - return true; - })} - {@const defaultSortKey = (scoring.arrTypes.includes('radarr') ? 'radarr' : scoring.arrTypes[0]) as SortKey} - {@const _applyDefaultSort = (() => { - if (!sortState && defaultSortKey) { - sortState = { key: defaultSortKey, direction: 'desc' }; - } - return null; - })()} - {@const sortedCustomFormats = sortFormats(filteredCustomFormats, state, sortState)} - {@const groupedFormats = groupFormats(sortedCustomFormats, selectedGroups)} -
unsavedChanges.markDirty()}> +{#if scoring} +
unsavedChanges.markDirty()}>
@@ -855,7 +810,7 @@
{/if}
-{/await} +{/if}