Skip to content

A platform for community discussion. Free, open, simple.

DEV: Prefer .pluck_first over .pluck.first (#13607)

Dan Ungureanu6ea4bbd2ec36
diff --git a/lib/topic_query.rb b/lib/topic_query.rb
index d296fc8f480..12e759a22c8 100644
--- a/lib/topic_query.rb
+++ b/lib/topic_query.rb
@@ -335,7 +335,7 @@ class TopicQuery
staff: user.staff?
)
- first_unread_pm_at = UserStat.where(user_id: user.id).pluck(:first_unread_pm_at).first
+ first_unread_pm_at = UserStat.where(user_id: user.id).pluck_first(:first_unread_pm_at)
list = list.where("topics.updated_at >= ?", first_unread_pm_at) if first_unread_pm_at
create_list(:private_messages, {}, list)
end
@@ -1013,7 +1013,7 @@ class TopicQuery
if params[:my_group_ids].present?
GroupUser.where(user_id: @user.id, group_id: params[:my_group_ids]).minimum(:first_unread_pm_at)
else
- UserStat.where(user_id: @user.id).pluck(:first_unread_pm_at).first
+ UserStat.where(user_id: @user.id).pluck_first(:first_unread_pm_at)
end
query = query.where("topics.updated_at >= ?", first_unread_pm_at) if first_unread_pm_at
diff --git a/script/import_scripts/base/lookup_container.rb b/script/import_scripts/base/lookup_container.rb
index caef17cd5a0..30ac96203d4 100644
--- a/script/import_scripts/base/lookup_container.rb
+++ b/script/import_scripts/base/lookup_container.rb
@@ -59,7 +59,7 @@ module ImportScripts
def find_username_by_import_id(import_id)
user_id = user_id_from_imported_user_id(import_id)
- User.where(id: user_id).pluck(:username).first if user_id.present?
+ User.where(id: user_id).pluck_first(:username) if user_id.present?
end
# Get the Discourse Category id based on the id of the source category
diff --git a/spec/helpers/application_helper_spec.rb b/spec/helpers/application_helper_spec.rb
index 5580077a47b..4a4c4002a60 100644
--- a/spec/helpers/application_helper_spec.rb
+++ b/spec/helpers/application_helper_spec.rb
@@ -406,7 +406,7 @@ describe ApplicationHelper do
end
it 'returns two color scheme link tags when dark mode is enabled' do
- SiteSetting.default_dark_mode_color_scheme_id = ColorScheme.where(name: "Dark").pluck(:id).first
+ SiteSetting.default_dark_mode_color_scheme_id = ColorScheme.where(name: "Dark").pluck_first(:id)
cs_stylesheets = helper.discourse_color_scheme_stylesheets
expect(cs_stylesheets).to include("(prefers-color-scheme: dark)")
@@ -462,7 +462,7 @@ describe ApplicationHelper do
helper.request.env[Auth::DefaultCurrentUserProvider::CURRENT_USER_KEY] = user
@new_cs = Fabricate(:color_scheme, name: 'Custom Color Scheme')
- SiteSetting.default_dark_mode_color_scheme_id = ColorScheme.where(name: "Dark").pluck(:id).first
+ SiteSetting.default_dark_mode_color_scheme_id = ColorScheme.where(name: "Dark").pluck_first(:id)
end
it "returns no dark scheme stylesheet when user has disabled that option" do
diff --git a/spec/models/topic_link_spec.rb b/spec/models/topic_link_spec.rb
index 6e52b74c231..099aa5a587a 100644
--- a/spec/models/topic_link_spec.rb
+++ b/spec/models/topic_link_spec.rb
@@ -58,8 +58,8 @@ describe TopicLink do
TopicLink.extract_from(post)
# we have a special rule for images title where we pull them out of the filename
- expect(topic.topic_links.where(url: png).pluck(:title).first).to eq(png_title)
- expect(topic.topic_links.where(url: non_png).pluck(:title).first).to eq("amazing")
+ expect(topic.topic_links.where(url: png).pluck_first(:title)).to eq(png_title)
+ expect(topic.topic_links.where(url: non_png).pluck_first(:title)).to eq("amazing")
expect(topic.topic_links.pluck(:url)).to contain_exactly(
png,