discourse/plugins/chat/app
Joffrey JAFFEUX 05aa55e172
DEV: moves logic from job to a service (#22691)
`Jobs::AutoJoinChannelBatch` was holding a lot of logic which should be in a service. Moreover, this refactoring is the opportunity to address a bug which could cause a duplicate key error.

From now when trying to insert a new membership it won't fail if a membership is already present.

Example error:

```
Job exception: ERROR:  duplicate key value violates unique constraint "user_chat_channel_unique_memberships"
DETAIL:  Key (user_id, chat_channel_id)=(1, 2) already exists.

Backtrace
rack-mini-profiler-3.1.0/lib/patches/db/pg.rb:110:in `exec'
rack-mini-profiler-3.1.0/lib/patches/db/pg.rb:110:in `async_exec'
(eval):29:in `async_exec'
mini_sql-1.4.0/lib/mini_sql/postgres/connection.rb:209:in `run'
mini_sql-1.4.0/lib/mini_sql/active_record_postgres/connection.rb:38:in `block in run'
mini_sql-1.4.0/lib/mini_sql/active_record_postgres/connection.rb:34:in `block in with_lock'
activesupport-7.0.5.1/lib/active_support/concurrency/load_interlock_aware_monitor.rb:25:in `handle_interrupt'
activesupport-7.0.5.1/lib/active_support/concurrency/load_interlock_aware_monitor.rb:25:in `block in synchronize'
activesupport-7.0.5.1/lib/active_support/concurrency/load_interlock_aware_monitor.rb:21:in `handle_interrupt'
activesupport-7.0.5.1/lib/active_support/concurrency/load_interlock_aware_monitor.rb:21:in `synchronize'
mini_sql-1.4.0/lib/mini_sql/active_record_postgres/connection.rb:34:in `with_lock'
mini_sql-1.4.0/lib/mini_sql/active_record_postgres/connection.rb:38:in `run'
mini_sql-1.4.0/lib/mini_sql/postgres/connection.rb:64:in `query_single'
/var/www/discourse/plugins/chat/app/jobs/regular/chat/auto_join_channel_batch.rb:38:in `execute'
```

Note this commit is also using main branch of `shoulda-matchers` as the gem has not been released yet.

Co-authored-by: Loïc Guitaut <5648+Flink@users.noreply.github.com>
2023-07-27 10:25:41 +02:00
..
controllers/chat FEATURE: thread pagination (#22624) 2023-07-27 09:57:03 +02:00
helpers/chat FEATURE: Mark all chat channels read with a shortcut (#20629) 2023-03-22 13:24:07 +10:00
jobs DEV: moves logic from job to a service (#22691) 2023-07-27 10:25:41 +02:00
models FEATURE: thread pagination (#22624) 2023-07-27 09:57:03 +02:00
policies DEV: Refactor DM channel creation into new service pattern (#22144) 2023-07-03 10:18:37 +10:00
queries/chat FEATURE: thread pagination (#22624) 2023-07-27 09:57:03 +02:00
serializers/chat FEATURE: thread pagination (#22624) 2023-07-27 09:57:03 +02:00
services DEV: moves logic from job to a service (#22691) 2023-07-27 10:25:41 +02:00
validators/chat DEV: properly namespace chat (#20690) 2023-03-17 14:24:38 +01:00
views DEV: Move discourse-chat to the core repo. (#18776) 2022-11-02 10:41:30 -03:00