discourse/spec
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
..
fabricators DEV: Apply syntax_tree formatting to spec/* 2023-01-09 11:49:28 +00:00
fixtures FEATURE: Show more context in Discourse topic oneboxes 2023-01-11 14:22:53 +01:00
helpers FEATURE: Show more context in Discourse topic oneboxes 2023-01-11 14:22:53 +01:00
import_export DEV: Apply syntax_tree formatting to spec/* 2023-01-09 11:49:28 +00:00
initializers DEV: Apply syntax_tree formatting to spec/* 2023-01-09 11:49:28 +00:00
integration Revert "DEV: Migrate existing cookies to Rails 7 format" 2023-01-12 12:07:49 +01:00
integrity FIX: Fix incorrect hashtag setting migration (#19857) 2023-01-16 10:53:00 +10:00
jobs DEV: extract anniversary badge query (#19716) 2023-01-16 11:55:00 +01:00
lib FIX: Fix incorrect hashtag setting migration (#19857) 2023-01-16 10:53:00 +10:00
mailers DEV: Apply syntax_tree formatting to spec/* 2023-01-09 11:49:28 +00:00
models DEV: Introduce enable_new_notifications_menu site setting (#19860) 2023-01-16 06:04:53 +08:00
multisite DEV: Apply syntax_tree formatting to spec/* 2023-01-09 11:49:28 +00:00
requests FIX: Fix incorrect hashtag setting migration (#19857) 2023-01-16 10:53:00 +10:00
script/import_scripts DEV: Apply syntax_tree formatting to spec/* 2023-01-09 11:49:28 +00:00
serializers DEV: Apply syntax_tree formatting to spec/* 2023-01-09 11:49:28 +00:00
services FIX: Fix flaky test resulting from PostAlerter keyword arguments (#19826) 2023-01-12 09:46:50 +08:00
support DEV: Apply syntax_tree formatting to spec/* 2023-01-09 11:49:28 +00:00
system FIX: Preload user sidebar attrs when ?enable_sidebar=1 (#19843) 2023-01-13 06:47:58 +08:00
tasks DEV: Apply syntax_tree formatting to spec/* 2023-01-09 11:49:28 +00:00
views DEV: Apply syntax_tree formatting to spec/* 2023-01-09 11:49:28 +00:00
rails_helper.rb DEV: Add option to disable rspec diff truncation ENV var (#19861) 2023-01-13 13:31:28 +10:00
regenerate_swagger_docs DEV: Add API docs for uploads and API doc watcher (#15387) 2021-12-23 08:40:15 +10:00
swagger_helper.rb DEV: Apply syntax_tree formatting to spec/* 2023-01-09 11:49:28 +00:00