# 수정: 404 토픽 캐시 삭제 시 Redis 키 순회 방지

**URL:** https://meta.discourse.org/t/fix-avoid-traversing-redis-keys-when-clearing-404-topic-cache/409622
**Category:** Bug
**Tags:** fixed
**Created:** [8월 9, 2026, 9:14오전 UTC](https://meta.discourse.org/t/fix-avoid-traversing-redis-keys-when-clearing-404-topic-cache/409622 "2026-08-09T09:14:29Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![small-lovely-cat](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/small-lovely-cat/32/553546_2.png) [@small-lovely-cat](https://meta.discourse.org/u/small-lovely-cat)
#### Post date: [8월 9, 2026, 9:14오전 UTC](https://meta.discourse.org/t/fix-avoid-traversing-redis-keys-when-clearing-404-topic-cache/409622/1 "2026-08-09T09:14:29Z")

</div>

#42413 에서 토픽의 캐시 무효화 로직이 재설계되었습니다.

그러나 `Discourse.cache.keys("page_not_found_topics:*").each { |key| Discourse.cache.redis.del(key) }`는 모든 Redis 키를 순회하므로 성능 문제를 일으킬 수 있으며, 키의 수가 많을 경우 타임아웃이 발생할 수 있습니다.

Redis DB가 큰 사이트에서는 사용자가 토픽을 제한된 카테고리로 이동할 때 500 오류를 경험할 수 있습니다.

 ![image](https://global.discourse-cdn.com/meta/original/4X/8/5/8/8581549a80b362a4ac9cfb146c057bf0834d7651.png)

이 커밋은 순회 범위를 전체 Redis보다 훨씬 작은 `Discourse.cache.normalize_key("page_not_found_topics:#{locale}")`로 제한하고, `scan_each`의 실행을 방지하기 위해 테스트를 추가합니다.

> <https://github.com/discourse/discourse/pull/42457>
>
> In #42413 , cache invalidation logic of topic is redesigned.
> 
> However, \`Discou…rse.cache.keys("page\_not\_found\_topics:\*").each { |key| Discourse.cache.redis.del(key) }\` will traverse all of the redis keys, causing performance issues, and may timeout if there are large amount of keys.
> 
> For a site with a large Redis DB, users may encounter 500 error when they move a topic to a restricted category.
> 
> \<img width="240" height="211" alt="image" src="https://github.com/user-attachments/assets/e16e87d0-2c1e-437e-99bf-521c5e4774a1" /\>
> 
> This commit restrict the traverse scope to \`Discourse.cache.normalize\_key("page\_not\_found\_topics:#{locale}")\`, which is far smaller than the whole redis, also add a test to avoid the execution of \`scan\_each\`.

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [8월 10, 2026, 1:51오전 UTC](https://meta.discourse.org/t/fix-avoid-traversing-redis-keys-when-clearing-404-topic-cache/409622/2 "2026-08-10T01:51:20Z")

</div>

정말 감사합니다, @zogstrip님이 병합했어요! 🤗

---

<div class="post-metadata">

### Author: ![Falco](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/falco/32/179432_2.png) [@Falco](https://meta.discourse.org/u/Falco)
#### Post date: [8월 10, 2026, 11:00오전 UTC](https://meta.discourse.org/t/fix-avoid-traversing-redis-keys-when-clearing-404-topic-cache/409622/3 "2026-08-10T11:00:17Z")

</div>

이 주제는 13시간 후 자동으로 닫혔습니다. 더 이상 새 답글을 작성할 수 없습니다.
