# stylesheet\_cache 目标泄露？

**URL:** <https://meta.discourse.org/t/leak-of-stylesheet-cache-targets/187957>\
**Category:** Development\
**Created:** [2021 年4 月 24 日 00:09 UTC](https://meta.discourse.org/t/leak-of-stylesheet-cache-targets/187957 "2021-04-24T00:09:26Z")\
**Posts on this page:** 1\
**Showing post:** 1

<div class="post-metadata">

作者： ![riking](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/riking/32/170938_2.png) [@riking](https://meta.discourse.org/u/riking)\
发布日期： [2021 年4 月 24 日 00:09 UTC](https://meta.discourse.org/t/leak-of-stylesheet-cache-targets/187957/1 "2021-04-24T00:09:27Z")

</div>

继续讨论 [PostgreSQL 13 更新](https://meta.discourse.org/t/postgresql-13-update/172563/125)：

> [@nildarar](#):
>
> |public|stylesheet\_cache|5826|

嗯，这个数字感觉有点高。Meta 表有 33k 行。让我们看看这个查询：

```sql
select count(*), target, max(updated_at) from stylesheet_cache
group by target
order by target, max(updated_at)

```

看起来我们对每个目标（target）设置了 50 个缓存样式表的上限，但不知为何，我们正在泄露 `target` 限定符？

| count | target | updated\_at |
| --- | --- | --- |
| 50 | discourse-adplugin\_37 | 2021-04-23T19:08:43.292Z |
| 50 | discourse-adplugin\_43 | 2021-04-23T19:08:52.227Z |
| 50 | discourse-adplugin\_54 | 2021-04-23T19:09:01.121Z |
| 50 | discourse-adplugin\_55 | 2021-04-23T19:09:10.245Z |
| 50 | discourse-adplugin\_57 | 2021-04-23T19:08:25.265Z |
| 6 | discourse-adplugin\_64 | **2021-01-01T11:49:49.071Z** |
| 50 | discourse-adplugin\_65 | **2020-09-21T16:23:50.647Z** |
| 50 | discourse-adplugin\_66 | 2021-04-23T19:08:34.562Z |
| 1 | discourse-adplugin\_71 | **2020-01-15T21:07:26.560Z** |
| 50 | discourse-adplugin\_72 | **2020-04-01T23:52:51.691Z** |
| 10 | discourse-adplugin\_75 | **2020-08-18T20:17:16.954Z** |
| 50 | discourse-adplugin\_77 | **2020-09-21T18:22:22.334Z** |
| 50 | discourse-adplugin\_9 | 2021-04-23T19:09:19.228Z |

此外，这一行显然是不正确的，但实际上无关紧要（我们只是比必要的时间更早开始执行删除操作）：

```diff
-count = StylesheetCache.count
+count = StylesheetCache.where(target: target).count
 if count > MAX_TO_KEEP
   ... code that deletes old entries, sharded on target ...

```

---

_[View the full topic](https://meta.discourse.org/t/leak-of-stylesheet-cache-targets/187957)._
