From f5718d0da4638aab9004441fa9ddcb0282410e2c Mon Sep 17 00:00:00 2001 From: juancarmore Date: Wed, 18 Jun 2025 13:48:16 +0200 Subject: [PATCH] backend: update archiveRoomMetadata method to conditionally update existing metadata --- backend/src/services/room.service.ts | 2 +- backend/src/services/storage/storage.service.ts | 15 +++++++++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/backend/src/services/room.service.ts b/backend/src/services/room.service.ts index 02c981f..d8977df 100644 --- a/backend/src/services/room.service.ts +++ b/backend/src/services/room.service.ts @@ -131,7 +131,7 @@ export class RoomService { await this.storageService.saveMeetRoom(room); // Update the archived room metadata if it exists - await this.storageService.archiveRoomMetadata(roomId); + await this.storageService.archiveRoomMetadata(roomId, true); return room; } diff --git a/backend/src/services/storage/storage.service.ts b/backend/src/services/storage/storage.service.ts index 0edb8b3..fda68ec 100644 --- a/backend/src/services/storage/storage.service.ts +++ b/backend/src/services/storage/storage.service.ts @@ -242,13 +242,15 @@ export class MeetStorageService< * This method retrieves the room data, extracts key metadata (moderator/publisher URLs and * recording preferences), and saves it to an archived location for future reference. * - * If an archived metadata for the room already exists, it will be overwritten. + * If `updateOnlyIfExists` is true, it will only save the archived metadata if it already exists, + * updating the existing entry. * * @param roomId - The unique identifier of the room to archive + * @param updateOnlyIfExists - If true, only update if archived metadata already exists * @throws {Error} When the room with the specified ID is not found * @returns A promise that resolves when the archiving operation completes successfully */ - async archiveRoomMetadata(roomId: string): Promise { + async archiveRoomMetadata(roomId: string, updateOnlyIfExists = false): Promise { const redisKey = RedisKeyName.ARCHIVED_ROOM + roomId; const storageKey = this.keyBuilder.buildArchivedMeetRoomKey(roomId); @@ -259,6 +261,15 @@ export class MeetStorageService< throw errorRoomNotFound(roomId); } + if (updateOnlyIfExists) { + const existing = await this.getFromCacheAndStorage>(redisKey, storageKey); + + if (!existing) { + this.logger.verbose(`Archived metadata for room ${roomId} does not exist, skipping update`); + return; + } + } + const archivedRoom: Partial = { moderatorRoomUrl: room.moderatorRoomUrl, publisherRoomUrl: room.publisherRoomUrl,