From b3ef5fe6e7262c72be806f4759962b9573aab844 Mon Sep 17 00:00:00 2001
From: Jason Rasmussen <jason@rasm.me>
Date: Mon, 9 Sep 2024 14:28:14 -0400
Subject: [PATCH] fix(server): handle multiple hierarchical subjects (#12509)

---
 server/src/services/metadata.service.spec.ts | 3 ++-
 server/src/services/metadata.service.ts      | 4 ++--
 2 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/server/src/services/metadata.service.spec.ts b/server/src/services/metadata.service.spec.ts
index 5b447c2355..8e865bd20f 100644
--- a/server/src/services/metadata.service.spec.ts
+++ b/server/src/services/metadata.service.spec.ts
@@ -453,7 +453,7 @@ describe(MetadataService.name, () => {
 
     it('should extract hierarchy from HierarchicalSubject', async () => {
       assetMock.getByIds.mockResolvedValue([assetStub.image]);
-      metadataMock.readTags.mockResolvedValue({ HierarchicalSubject: ['Parent|Child'] });
+      metadataMock.readTags.mockResolvedValue({ HierarchicalSubject: ['Parent|Child', 'TagA'] });
       tagMock.upsertValue.mockResolvedValueOnce(tagStub.parent);
       tagMock.upsertValue.mockResolvedValueOnce(tagStub.child);
 
@@ -465,6 +465,7 @@ describe(MetadataService.name, () => {
         value: 'Parent/Child',
         parent: tagStub.parent,
       });
+      expect(tagMock.upsertValue).toHaveBeenNthCalledWith(3, { userId: 'user-id', value: 'TagA', parent: undefined });
     });
 
     it('should extract ignore / characters in a HierarchicalSubject tag', async () => {
diff --git a/server/src/services/metadata.service.ts b/server/src/services/metadata.service.ts
index cf51a332f8..83f0abd79b 100644
--- a/server/src/services/metadata.service.ts
+++ b/server/src/services/metadata.service.ts
@@ -384,12 +384,12 @@ export class MetadataService {
   }
 
   private async applyTagList(asset: AssetEntity, exifTags: ImmichTags) {
-    const tags: unknown[] = [];
+    const tags: Array<string | number> = [];
     if (exifTags.TagsList) {
       tags.push(...exifTags.TagsList);
     } else if (exifTags.HierarchicalSubject) {
       tags.push(
-        exifTags.HierarchicalSubject.map((tag) =>
+        ...exifTags.HierarchicalSubject.map((tag) =>
           tag
             // convert | to /
             .replaceAll('/', '<PLACEHOLDER>')