FIX: Properly support defaults for upload site settings.

FIX: Properly support defaults for upload site settings.

diff --git a/app/assets/javascripts/discourse/widgets/home-logo.js.es6 b/app/assets/javascripts/discourse/widgets/home-logo.js.es6
index 86bc339..5c7454d 100644
--- a/app/assets/javascripts/discourse/widgets/home-logo.js.es6
+++ b/app/assets/javascripts/discourse/widgets/home-logo.js.es6
@@ -17,7 +17,7 @@ export default createWidget("home-logo", {
   },
 
   logoUrl() {
-    return this.siteSettings.site_home_logo_url || "";
+    return this.siteSettings.site_logo_url || "";
   },
 
   mobileLogoUrl() {
diff --git a/app/controllers/admin/site_settings_controller.rb b/app/controllers/admin/site_settings_controller.rb
index d12405f..3a894e1 100644
--- a/app/controllers/admin/site_settings_controller.rb
+++ b/app/controllers/admin/site_settings_controller.rb
@@ -15,7 +15,7 @@ class Admin::SiteSettingsController < Admin::AdminController
     raise_access_hidden_setting(id)
 
     if SiteSetting.type_supervisor.get_type(id) == :upload
-      value = Upload.get_from_url(value) || ''
+      value = Upload.find_by(url: value) || ''
     end
 
     SiteSetting.set_and_log(id, value, current_user)
diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb
index 38b826b..81d28e9 100644
--- a/app/helpers/application_helper.rb
+++ b/app/helpers/application_helper.rb
@@ -219,7 +219,7 @@ module ApplicationHelper
         opts[:twitter_summary_large_image] = twitter_summary_large_image_url
       end
 
-      opts[:image] = SiteSetting.opengraph_image_url.presence ||
+      opts[:image] = SiteSetting.site_opengraph_image_url.presence ||
         twitter_summary_large_image_url.presence ||
         SiteSetting.site_large_icon_url.presence ||
         SiteSetting.site_apple_touch_icon_url.presence ||
@@ -295,7 +295,7 @@ module ApplicationHelper
       if mobile_view? && SiteSetting.site_mobile_logo_url
         SiteSetting.site_mobile_logo_url
       else
-        SiteSetting.site_home_logo_url
+        SiteSetting.site_logo_url
       end
     end
   end
diff --git a/app/helpers/user_notifications_helper.rb b/app/helpers/user_notifications_helper.rb
index e3aed77..575635f 100644
--- a/app/helpers/user_notifications_helper.rb
+++ b/app/helpers/user_notifications_helper.rb
@@ -22,8 +22,7 @@ module UserNotificationsHelper
     logo_url = SiteSetting.site_digest_logo_url
     logo_url = SiteSetting.site_logo_url if logo_url.blank? || logo_url =~ /\.svg$/i
     return nil if logo_url.blank? || logo_url =~ /\.svg$/i
-
-    full_cdn_url(logo_url)
+    logo_url
   end
 
   def html_site_link(color)
diff --git a/app/jobs/scheduled/clean_up_uploads.rb b/app/jobs/scheduled/clean_up_uploads.rb
index 3c4f37c..2043c43 100644
--- a/app/jobs/scheduled/clean_up_uploads.rb
+++ b/app/jobs/scheduled/clean_up_uploads.rb
@@ -7,6 +7,7 @@ module Jobs
 
       # always remove invalid upload records
       Upload
+        .by_users
         .where("retain_hours IS NULL OR created_at < current_timestamp - interval '1 hour' * retain_hours")
         .where("created_at < ?", grace_period.hour.ago)
         .where(url: "")
@@ -44,7 +45,8 @@ module Jobs
         end
       end.compact.uniq
 
-      result = Upload.where("uploads.retain_hours IS NULL OR uploads.created_at < current_timestamp - interval '1 hour' * uploads.retain_hours")
+      result = Upload.by_users
+        .where("uploads.retain_hours IS NULL OR uploads.created_at < current_timestamp - interval '1 hour' * uploads.retain_hours")
         .where("uploads.created_at < ?", grace_period.hour.ago)
         .joins(<<~SQL)
           LEFT JOIN site_settings ss
diff --git a/app/models/report.rb b/app/models/report.rb
index e34efd5..e0410ef 100644
--- a/app/models/report.rb
+++ b/app/models/report.rb
@@ -1529,7 +1529,9 @@ class Report
     FROM uploads up
     JOIN users u
     ON u.id = up.user_id
-    WHERE up.created_at >= '#{report.start_date}' AND up.created_at <= '#{report.end_date}'
+    WHERE up.created_at >= '#{report.start_date}'
+    AND up.created_at <= '#{report.end_date}'
+    AND up.id > #{Upload::SEEDED_ID_THRESHOLD}
     ORDER BY up.filesize DESC
     LIMIT #{report.limit || 250}
     SQL
diff --git a/app/models/site_setting.rb b/app/models/site_setting.rb
index 49b9281..031fd5a 100644
--- a/app/models/site_setting.rb
+++ b/app/models/site_setting.rb
@@ -175,69 +175,26 @@ class SiteSetting < ActiveRecord::Base
     site_logo_small_url
     site_mobile_logo_url
     site_favicon_url
-    site_home_logo_url
   }.each { |client_setting| client_settings << client_setting }
 
-  def self.site_home_logo_url
-    upload = SiteSetting.logo
-
-    if SiteSetting.defaults.get(:title) != SiteSetting.title && !upload
-      ''
-    else
-      full_cdn_url(upload ? upload.url : '/images/d-logo-sketch.png')
+  %i{
+    logo
+    logo_small
+    digest_logo
+    mobile_logo
+    large_icon
+    favicon
+    apple_touch_icon
+    twitter_summary_large_image
+    opengraph_image
+    push_notifications_icon
+  }.each do |setting_name|
+    define_singleton_method("site_#{setting_name}_url") do
+      upload = self.public_send(setting_name)
+      upload ? full_cdn_url(upload.url) : ''
     end
   end
 
-  def self.site_logo_url
-    upload = self.logo
-    upload ? full_cdn_url(upload.url) : self.logo_url(warn: false)
-  end
-
-  def self.site_logo_small_url
-    upload = self.logo_small
-    upload ? full_cdn_url(upload.url) : self.logo_small_url(warn: false)
-  end
-
-  def self.site_digest_logo_url
-    upload = self.digest_logo
-    upload ? full_cdn_url(upload.url) : self.digest_logo_url(warn: false)
-  end
-
-  def self.site_mobile_logo_url
-    upload = self.mobile_logo
-    upload ? full_cdn_url(upload.url) : self.mobile_logo_url(warn: false)
-  end
-
-  def self.site_large_icon_url
-    upload = self.large_icon
-    upload ? full_cdn_url(upload.url) : self.large_icon_url(warn: false)
-  end
-
-  def self.site_favicon_url
-    upload = self.favicon
-    upload ? full_cdn_url(upload.url) : self.favicon_url(warn: false)
-  end
-
-  def self.site_apple_touch_icon_url
-    upload = self.apple_touch_icon
-    upload ? full_cdn_url(upload.url) : self.apple_touch_icon_url(warn: false)
-  end
-
-  def self.opengraph_image_url
-    upload = self.opengraph_image
-    upload ? full_cdn_url(upload.url) : self.default_opengraph_image_url(warn: false)
-  end
-
-  def self.site_twitter_summary_large_image_url
-    self.twitter_summary_large_image&.url ||
-      self.twitter_summary_large_image_url(warn: false)
-  end
-
-  def self.site_push_notifications_icon_url
-    SiteSetting.push_notifications_icon&.url ||
-      SiteSetting.push_notifications_icon_url(warn: false)
-  end
-
   def self.shared_drafts_enabled?
     c = SiteSetting.shared_drafts_category
     c.present? && c.to_i != SiteSetting.uncategorized_category_id.to_i
diff --git a/app/models/upload.rb b/app/models/upload.rb
index 3cf5fb6..262d0e2 100644
--- a/app/models/upload.rb
+++ b/app/models/upload.rb
@@ -10,6 +10,7 @@ class Upload < ActiveRecord::Base
   include ActionView::Helpers::NumberHelper
 
   SHA1_LENGTH = 40
+  SEEDED_ID_THRESHOLD = 0
 
   belongs_to :user
 
@@ -36,6 +37,8 @@ class Upload < ActiveRecord::Base
     UserAvatar.where(custom_upload_id: self.id).update_all(custom_upload_id: nil)
   end
 
+  scope :by_users, -> { where("uploads.id > ?", SEEDED_ID_THRESHOLD) }
+
   def to_s
     self.url
   end
diff --git a/app/services/push_notification_pusher.rb b/app/services/push_notification_pusher.rb
index a7d562f..4473240 100644
--- a/app/services/push_notification_pusher.rb
+++ b/app/services/push_notification_pusher.rb
@@ -67,8 +67,8 @@ class PushNotificationPusher
   protected
 
   def self.get_badge
-    if SiteSetting.site_push_notifications_icon_url.present?
-      SiteSetting.site_push_notifications_icon_url
+    if (url = SiteSetting.site_push_notifications_icon_url).present?
+      url
     else
       ActionController::Base.helpers.image_url("push-notifications/discourse.png")
     end
diff --git a/config/site_settings.yml b/config/site_settings.yml
index cc8a362..840dfd6 100644

[... diff too long, it was truncated ...]

GitHub sha: b0c8fdd7

This commit has been mentioned on Discourse Meta. There might be relevant details there:

This commit has been mentioned on Discourse Meta. There might be relevant details there: