From 8a2309ba7d81b50ab8fac5bca02f32d2f9f6ac75 Mon Sep 17 00:00:00 2001
From: taichan <40626578+taichanNE30@users.noreply.github.com>
Date: Fri, 27 Oct 2023 18:37:17 +0900
Subject: [PATCH] =?UTF-8?q?fix(backend):=20=E3=83=8F=E3=83=83=E3=82=B7?=
 =?UTF-8?q?=E3=83=A5=E3=82=BF=E3=82=B0=E3=81=AE=E3=83=A9=E3=83=B3=E3=82=AD?=
 =?UTF-8?q?=E3=83=B3=E3=82=B0=E3=81=AE=E5=95=8F=E3=81=84=E5=90=88=E3=82=8F?=
 =?UTF-8?q?=E3=81=9B=E7=B5=90=E6=9E=9C=E3=81=8C=E3=81=AA=E3=81=84=E3=81=A8?=
 =?UTF-8?q?=E3=81=8D=E3=81=AE=E3=82=A8=E3=83=A9=E3=83=BC=E4=BF=AE=E6=AD=A3?=
 =?UTF-8?q?=20(#12145)?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

* fix(backend): undefined result error

* Update Changelog

* Update packages/backend/src/core/FeaturedService.ts

Co-authored-by: syuilo <Syuilotan@yahoo.co.jp>

---------

Co-authored-by: syuilo <Syuilotan@yahoo.co.jp>
---
 CHANGELOG.md                                 | 1 +
 packages/backend/src/core/FeaturedService.ts | 2 +-
 2 files changed, 2 insertions(+), 1 deletion(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 9a1b2bc96..67ec9ee8e 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -33,6 +33,7 @@
 - Fix: 自分のフォローしているユーザーの自分のフォローしていないユーザーの visibility: followers な投稿への返信がストリーミングで流れてくる問題を修正
 - Fix: RedisへのTLキャッシュが有効の場合にHTL/LTL/STLが空になることがある問題を修正
 - Fix: STLでフォローしていないチャンネルが取得される問題を修正
+- Fix: `hashtags/trend`にてRedisからトレンドの情報が取得できない際にInternal Server Errorになる問題を修正
 - Fix: フォローしているチャンネルをフォロー解除した時(またはその逆)、タイムラインに反映される間隔を改善
 
 ## 2023.10.2
diff --git a/packages/backend/src/core/FeaturedService.ts b/packages/backend/src/core/FeaturedService.ts
index cccbbd95c..9617f8388 100644
--- a/packages/backend/src/core/FeaturedService.ts
+++ b/packages/backend/src/core/FeaturedService.ts
@@ -52,7 +52,7 @@ export class FeaturedService {
 			`${name}:${currentWindow}`, 0, threshold, 'REV', 'WITHSCORES');
 		redisPipeline.zrange(
 			`${name}:${previousWindow}`, 0, threshold, 'REV', 'WITHSCORES');
-		const [currentRankingResult, previousRankingResult] = await redisPipeline.exec().then(result => result ? result.map(r => r[1] as string[]) : [[], []]);
+		const [currentRankingResult, previousRankingResult] = await redisPipeline.exec().then(result => result ? result.map(r => (r[1] ?? []) as string[]) : [[], []]);
 
 		const ranking = new Map<string, number>();
 		for (let i = 0; i < currentRankingResult.length; i += 2) {