mirror of
https://github.com/discourse/discourse.git
synced 2025-05-22 04:41:25 +08:00
DEV: pluck_first
Doing .pluck(:column).first is a very common pattern in Discourse and in most cases, a limit cause isn't being added. Instead of adding a limit clause to all these callsites, this commit adds two new methods to ActiveRecord::Relation: pluck_first, equivalent to limit(1).pluck(*columns).first and pluck_first! which, like other finder methods, raises an exception when no record is found
This commit is contained in:
@ -21,7 +21,7 @@ class ThemeJavascriptsController < ApplicationController
|
||||
cache_file = "#{DISK_CACHE_PATH}/#{params[:digest]}.js"
|
||||
|
||||
unless File.exist?(cache_file)
|
||||
content = query.pluck(:content).first
|
||||
content = query.pluck_first(:content)
|
||||
raise Discourse::NotFound if content.nil?
|
||||
|
||||
FileUtils.mkdir_p(DISK_CACHE_PATH)
|
||||
@ -41,7 +41,7 @@ class ThemeJavascriptsController < ApplicationController
|
||||
end
|
||||
|
||||
def last_modified
|
||||
@last_modified ||= query.pluck(:updated_at).first
|
||||
@last_modified ||= query.pluck_first(:updated_at)
|
||||
end
|
||||
|
||||
def not_modified?
|
||||
|
Reference in New Issue
Block a user