mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
DEV: Replace #pluck_first freedom patch with AR #pick in core (#19893)
The #pluck_first freedom patch, first introduced by @danielwaterworth has served us well, and is used widely throughout both core and plugins. It seems to have been a common enough use case that Rails 6 introduced it's own method #pick with the exact same implementation. This allows us to retire the freedom patch and switch over to the built-in ActiveRecord method. There is no replacement for #pluck_first!, but a quick search shows we are using this in a very limited capacity, and in some cases incorrectly (by assuming a nil return rather than an exception), which can quite easily be replaced with #pick plus some extra handling.
This commit is contained in:
@@ -252,7 +252,7 @@ class Draft < ActiveRecord::Base
|
||||
reply = JSON.parse(data)["reply"] || ""
|
||||
return if reply.length < SiteSetting.backup_drafts_to_pm_length
|
||||
|
||||
post_id = BackupDraftPost.where(user_id: user.id, key: key).pluck_first(:post_id)
|
||||
post_id = BackupDraftPost.where(user_id: user.id, key: key).pick(:post_id)
|
||||
post = Post.where(id: post_id).first if post_id
|
||||
|
||||
BackupDraftPost.where(user_id: user.id, key: key).delete_all if post_id && !post
|
||||
@@ -305,7 +305,7 @@ class Draft < ActiveRecord::Base
|
||||
end
|
||||
|
||||
def self.ensure_draft_topic!(user)
|
||||
topic_id = BackupDraftTopic.where(user_id: user.id).pluck_first(:topic_id)
|
||||
topic_id = BackupDraftTopic.where(user_id: user.id).pick(:topic_id)
|
||||
topic = Topic.find_by(id: topic_id) if topic_id
|
||||
|
||||
BackupDraftTopic.where(user_id: user.id).delete_all if topic_id && !topic
|
||||
|
||||
Reference in New Issue
Block a user