# Leak of stylesheet\_cache targets?

**URL:** https://meta.discourse.org/t/leak-of-stylesheet-cache-targets/187957
**Category:** Development
**Created:** [April 24, 2021, 12:09am UTC](https://meta.discourse.org/t/leak-of-stylesheet-cache-targets/187957 "2021-04-24T00:09:26Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![riking](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/riking/32/170938_2.png) [@riking](https://meta.discourse.org/u/riking)
#### Post date: [April 24, 2021, 12:09am UTC](https://meta.discourse.org/t/leak-of-stylesheet-cache-targets/187957/1 "2021-04-24T00:09:27Z")

</div>

Continuing the discussion from [PostgreSQL 13 update](https://meta.discourse.org/t/postgresql-13-update/172563/125):

> [@PostgreSQL 13 update](https://meta.discourse.org/t/postgresql-13-update/172563/125):
>
> |public|stylesheet\_cache|5826|

Huh, that feels a little high. Meta has 33k rows. Taking a look at this query:

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

```

It looks like we have a retention cap of 50 cached stylesheets per target, but we’re leaking `target` specifiers, somehow?

| 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 |

Additionally, this line is clearly incorrect, but it doesn’t actually matter (we just start performing the deletes sooner than necessary):

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

```
