From 01a9f735c8be380438833e6bdc6a8610ecbda6ab Mon Sep 17 00:00:00 2001 From: Arpit Singh <3810664+ufizo@users.noreply.github.com> Date: Thu, 7 Aug 2025 06:43:23 -0600 Subject: [PATCH] fix: avoid unnecessary writes to system metadata repository (#20538) Co-authored-by: Zack Pollard --- server/src/services/storage.service.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/server/src/services/storage.service.ts b/server/src/services/storage.service.ts index 5b08204bf9..b983c34f62 100644 --- a/server/src/services/storage.service.ts +++ b/server/src/services/storage.service.ts @@ -96,9 +96,10 @@ export class StorageService extends BaseService { await this.databaseRepository.withLock(DatabaseLock.MediaLocation, async () => { const current = StorageCore.getMediaLocation(); const samples = await this.assetRepository.getFileSamples(); + const savedValue = await this.systemMetadataRepository.get(SystemMetadataKey.MediaLocation); if (samples.length > 0) { const path = samples[0].path; - const savedValue = await this.systemMetadataRepository.get(SystemMetadataKey.MediaLocation); + let previous = savedValue?.location || ''; if (!previous && this.configRepository.getEnv().storage.mediaLocation) { @@ -125,7 +126,10 @@ export class StorageService extends BaseService { } } - await this.systemMetadataRepository.set(SystemMetadataKey.MediaLocation, { location: current }); + // Only set MediaLocation in systemMetadataRepository if needed + if (savedValue?.location !== current) { + await this.systemMetadataRepository.set(SystemMetadataKey.MediaLocation, { location: current }); + } }); }