PERF: Avoid running a pointless PG query when theme has no variables. (#13342)
When `Theme#all_theme_variables` returns an empty array, we were running a pointless query in `StyleSheet::Manager#uploads_digest`. `SELECT "sha1" FROM "theme_fields" INNER JOIN "uploads" ON "uploads"."id" = "theme_fields"."upload_id" WHERE 1=0`
This commit is contained in:
parent
0ae8640650
commit
2a4a20ad67
|
@ -434,7 +434,18 @@ class Stylesheet::Manager
|
|||
end
|
||||
|
||||
def uploads_digest
|
||||
Digest::SHA1.hexdigest(ThemeField.joins(:upload).where(id: theme&.all_theme_variables).pluck(:sha1).join(","))
|
||||
sha1s =
|
||||
if (theme_ids = theme&.all_theme_variables).present?
|
||||
ThemeField
|
||||
.joins(:upload)
|
||||
.where(id: theme_ids)
|
||||
.pluck(:sha1)
|
||||
.join(",")
|
||||
else
|
||||
""
|
||||
end
|
||||
|
||||
Digest::SHA1.hexdigest(sha1s)
|
||||
end
|
||||
|
||||
def color_scheme_digest
|
||||
|
|
Loading…
Reference in New Issue