discourse/app
Régis Hanol b704e338ef
DEV: extract anniversary badge query (#19716)
So it can easily be overwritten in a plugin for example.

### Added more tests to provide better coverage

We previously only had `u.silenced_till IS NULL` but I made it consistent with pretty much every other places where we check for "active" users.

These two new lines do change the query a tiny bit though. 

**Before** 

- You could not get the badge if you were currently silenced (no matter what period is being checked)
- You could get the badge if you were suspended 😬 

**After**

- You can't get the badge if you were silenced during the past year
- You can't get the badge if you were suspended during the past year


### Improved the performance of the query by using `NOT EXISTS` instead of `LEFT JOIN / COUNT() = 0`

There is no difference in behaviour between 

```sql
LEFT JOIN user_badges AS ub ON ub.user_id = u.id AND ...
[...]
HAVING COUNT(ub.*) = 0
```

and

```sql
NOT EXISTS (SELECT 1 FROM user_badges AS ub WHERE ub.user_id = u.id AND ...)
```

The only difference is performance-wise. The `NOT EXISTS` is 10-30% faster on very large databases (aka. posts and users in X millions). I checked on 3 of the largest datasets I could find.
2023-01-16 11:55:00 +01:00
..
assets UX: fix alignment issues with autocomplete (#19828) 2023-01-16 09:09:23 +11:00
controllers FEATURE: Extend topic update API scope to allow status updates (#19654) 2023-01-13 01:21:04 +00:00
helpers FEATURE: Show more context in Discourse topic oneboxes 2023-01-11 14:22:53 +01:00
jobs DEV: extract anniversary badge query (#19716) 2023-01-16 11:55:00 +01:00
mailers DEV: Apply syntax_tree formatting to app/* 2023-01-09 14:14:59 +00:00
models DEV: Introduce enable_new_notifications_menu site setting (#19860) 2023-01-16 06:04:53 +08:00
serializers FIX: Preload user sidebar attrs when ?enable_sidebar=1 (#19843) 2023-01-13 06:47:58 +08:00
services DEV: Remove defunct TODOs (#19825) 2023-01-12 09:41:39 +10:00
views FEATURE: Show more context in Discourse topic oneboxes 2023-01-11 14:22:53 +01:00