From 77237b54ac2ed597245c1e196022351a58ca46a9 Mon Sep 17 00:00:00 2001 From: Sam Chau Date: Fri, 2 Jan 2026 20:20:55 +1030 Subject: [PATCH] feat(logging): enhance logging for delay profile updates and write operations --- .../pcd/queries/delayProfiles/update.ts | 37 +++++++++++++++++++ src/lib/server/pcd/writer.ts | 25 ++++++++++++- 2 files changed, 60 insertions(+), 2 deletions(-) diff --git a/src/lib/server/pcd/queries/delayProfiles/update.ts b/src/lib/server/pcd/queries/delayProfiles/update.ts index 67fd6d0..0ceccc2 100644 --- a/src/lib/server/pcd/queries/delayProfiles/update.ts +++ b/src/lib/server/pcd/queries/delayProfiles/update.ts @@ -5,6 +5,7 @@ import type { PCDCache } from '../../cache.ts'; import { writeOperation, type OperationLayer } from '../../writer.ts'; import type { PreferredProtocol, DelayProfileTableRow } from './types.ts'; +import { logger } from '$logger/logger.ts'; export interface UpdateDelayProfileInput { name: string; @@ -113,6 +114,42 @@ export async function update(options: UpdateDelayProfileOptions) { queries.push(linkTag); } + // Log what's being changed (before the write) + const changes: Record = {}; + + if (current.name !== input.name) { + changes.name = { from: current.name, to: input.name }; + } + if (current.preferred_protocol !== input.preferredProtocol) { + changes.preferredProtocol = { from: current.preferred_protocol, to: input.preferredProtocol }; + } + if (current.usenet_delay !== usenetDelay) { + changes.usenetDelay = { from: current.usenet_delay, to: usenetDelay }; + } + if (current.torrent_delay !== torrentDelay) { + changes.torrentDelay = { from: current.torrent_delay, to: torrentDelay }; + } + if (current.bypass_if_highest_quality !== input.bypassIfHighestQuality) { + changes.bypassIfHighestQuality = { from: current.bypass_if_highest_quality, to: input.bypassIfHighestQuality }; + } + if (current.bypass_if_above_custom_format_score !== input.bypassIfAboveCfScore) { + changes.bypassIfAboveCfScore = { from: current.bypass_if_above_custom_format_score, to: input.bypassIfAboveCfScore }; + } + if (current.minimum_custom_format_score !== minimumCfScore) { + changes.minimumCfScore = { from: current.minimum_custom_format_score, to: minimumCfScore }; + } + if (tagsToAdd.length > 0 || tagsToRemove.length > 0) { + changes.tags = { from: currentTagNames, to: input.tags }; + } + + await logger.info(`Save delay profile "${input.name}"`, { + source: 'DelayProfile', + meta: { + id: current.id, + changes + } + }); + // Write the operation with metadata // Include previousName if this is a rename const isRename = input.name !== current.name; diff --git a/src/lib/server/pcd/writer.ts b/src/lib/server/pcd/writer.ts index 1eb27c5..f81f01f 100644 --- a/src/lib/server/pcd/writer.ts +++ b/src/lib/server/pcd/writer.ts @@ -301,9 +301,30 @@ export async function writeOperation(options: WriteOptions): Promise