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

This commit is contained in:
Dan Ungureanu 2021-07-02 05:03:54 +03:00 committed by GitHub
parent 3db4ed113b
commit 6ea4bbd2ec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 7 additions and 7 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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,