Forráskód Böngészése

fix(homepage): enhance getCategoryTags method with logging and improved structure

Dave 1 hónapja
szülő
commit
3c68fcac3d
1 módosított fájl, 19 hozzáadás és 15 törlés
  1. 19 15
      apps/box-app-api/src/feature/homepage/homepage.service.ts

+ 19 - 15
apps/box-app-api/src/feature/homepage/homepage.service.ts

@@ -309,43 +309,47 @@ export class HomepageService {
     return this.videoService.getCategories();
   }
 
-  async getCategoryTags(
-    channelId: string
-  ): Promise<any[]> {
+  async getCategoryTags(channelId: string): Promise<any[]> {
     try {
       const cacheKey = `category:tag:${channelId}`;
       const cache = await this.redis.getJson<HomeCategoryCacheItem[]>(cacheKey);
       if (cache) {
         return cache;
       }
-      
+
+      this.logger.log(`Cache miss for category tags of channelId=${channelId}`);
+
       const channel = await this.prisma.channel.findUnique({
         where: { channelId },
-        select: {
-          categories: true
-        }
+        // select: {
+        //   categories: true,
+        // },
       });
+      this.logger.log(
+        `Fetched channel data for channelId=${channelId}: ${JSON.stringify(channel)}`,
+      );
 
       type ChannelCategory = {
-        id: string
-        name?: string
+        id: string;
+        name?: string;
       };
 
       const categoryIds =
-        (channel?.categories as ChannelCategory[] | null)?.map(c => c.id) ?? [];
+        (channel?.categories as ChannelCategory[] | null)?.map((c) => c.id) ??
+        [];
 
       const categories = await this.prisma.category.findMany({
         where: {
-          id: { in: categoryIds }
+          id: { in: categoryIds },
         },
         select: {
           name: true,
           subtitle: true,
-          tagNames: true
+          tagNames: true,
         },
         orderBy: {
-          seq: 'desc'
-        }
+          seq: 'desc',
+        },
       });
 
       if (categories.length > 0) {
@@ -360,7 +364,7 @@ export class HomepageService {
       );
       return [];
     }
-  }  
+  }
 
   async getCategoryList(): Promise<HomeCategoryCacheItem[]> {
     const raw = await this.redis.get(tsCacheKeys.category.all());