mirror of
https://github.com/discourse/discourse.git
synced 2025-05-28 13:51:18 +08: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:
@ -22,7 +22,7 @@ class ThemeJavascriptsController < ApplicationController
|
||||
cache_file = "#{DISK_CACHE_PATH}/#{params[:digest]}.js"
|
||||
|
||||
write_if_not_cached(cache_file) do
|
||||
content, has_source_map = query.pluck_first(:content, "source_map IS NOT NULL")
|
||||
content, has_source_map = query.pick(:content, "source_map IS NOT NULL")
|
||||
if has_source_map
|
||||
content +=
|
||||
"\n//# sourceMappingURL=#{params[:digest]}.map?__ws=#{Discourse.current_hostname}\n"
|
||||
@ -40,7 +40,7 @@ class ThemeJavascriptsController < ApplicationController
|
||||
# Security: safe due to route constraint
|
||||
cache_file = "#{DISK_CACHE_PATH}/#{params[:digest]}.map"
|
||||
|
||||
write_if_not_cached(cache_file) { query.pluck_first(:source_map) }
|
||||
write_if_not_cached(cache_file) { query.pick(:source_map) }
|
||||
|
||||
serve_file(cache_file)
|
||||
end
|
||||
@ -75,7 +75,7 @@ class ThemeJavascriptsController < ApplicationController
|
||||
if params[:action].to_s == "show_tests"
|
||||
File.exist?(@cache_file) ? File.ctime(@cache_file) : nil
|
||||
else
|
||||
query.pluck_first(:updated_at)
|
||||
query.pick(:updated_at)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user