discourse/plugins/chat/app/jobs/regular/chat
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
..
auto_join_channel_batch.rb DEV: moves logic from job to a service (#22691) 2023-07-27 10:25:41 +02:00
auto_join_channel_memberships.rb
auto_remove_membership_handle_category_updated.rb
auto_remove_membership_handle_chat_allowed_groups_change.rb
auto_remove_membership_handle_destroyed_group.rb
auto_remove_membership_handle_user_removed_from_group.rb
channel_archive.rb
channel_delete.rb DEV: Refactor STI/polymorphic associations in chat (#20789) 2023-04-17 15:41:56 +02:00
delete_user_messages.rb
kick_users_from_channel.rb
mark_all_channel_threads_read.rb DEV: Remove experimental site setting for chat threads (#22720) 2023-07-26 12:46:23 +02:00
notify_mentioned.rb FIX: Thread mention read state and notification links (#21385) 2023-05-04 17:28:51 +02:00
notify_watching.rb DEV: check if user can_chat inside the can_join_chat_channel guardian (#21812) 2023-07-19 21:55:00 +04:00
process_message.rb
send_message_notifications.rb
update_channel_user_count.rb
update_thread_reply_count.rb DEV: Remove experimental site setting for chat threads (#22720) 2023-07-26 12:46:23 +02:00