From 9d11ccc42e5886e9d5af21b98dcaf49177acbdd6 Mon Sep 17 00:00:00 2001 From: Akshay Date: Tue, 19 Aug 2014 07:28:21 +0530 Subject: [PATCH] removed usless access modifiers specified in models --- app/models/admin_dashboard_data.rb | 9 +-- app/models/category_featured_topic.rb | 15 ++-- app/models/category_user.rb | 2 - app/models/draft.rb | 2 - app/models/error_log.rb | 2 - app/models/global_setting.rb | 2 - app/models/locale_site_setting.rb | 3 - app/models/plugin_store.rb | 4 - app/models/post_action.rb | 2 - app/models/s3_region_site_setting.rb | 2 - app/models/top_topic.rb | 101 +++++++++++++------------- app/models/trust_level_setting.rb | 2 - app/models/user_action.rb | 2 - 13 files changed, 61 insertions(+), 87 deletions(-) diff --git a/app/models/admin_dashboard_data.rb b/app/models/admin_dashboard_data.rb index cd5b4eaff..e44346574 100644 --- a/app/models/admin_dashboard_data.rb +++ b/app/models/admin_dashboard_data.rb @@ -194,14 +194,13 @@ class AdminDashboardData I18n.t(i18n_key) end end + def self.report_access_password_removal $redis.setex access_password_removal_key, 172_800, 'dashboard.access_password_removal' end - private - - def self.access_password_removal_key - 'dash-data:access_password_removal' - end + def self.access_password_removal_key + 'dash-data:access_password_removal' + end end diff --git a/app/models/category_featured_topic.rb b/app/models/category_featured_topic.rb index 2324a9fd3..524f35583 100644 --- a/app/models/category_featured_topic.rb +++ b/app/models/category_featured_topic.rb @@ -35,14 +35,13 @@ class CategoryFeaturedTopic < ActiveRecord::Base end end - private - def self.fake_admin - # fake an admin - admin = User.new - admin.admin = true - admin.id = -1 - admin - end + def self.fake_admin + # fake an admin + admin = User.new + admin.admin = true + admin.id = -1 + admin + end end diff --git a/app/models/category_user.rb b/app/models/category_user.rb index 830787caf..1b65dccfb 100644 --- a/app/models/category_user.rb +++ b/app/models/category_user.rb @@ -60,8 +60,6 @@ class CategoryUser < ActiveRecord::Base end end - private - def self.apply_default_to_topic(topic, level, reason) # Can not afford to slow down creation of topics when a pile of users are watching new topics, reverting to SQL for max perf here sql = <= :from AND deleted_at IS NULL @@ -91,20 +90,20 @@ class TopTopic < ActiveRecord::Base AND user_id <> #{Discourse.system_user.id} GROUP BY topic_id" - TopTopic.update_top_topics(period, "posts", sql) - end + TopTopic.update_top_topics(period, "posts", sql) + end - def self.update_views_count_for(period) - sql = "SELECT topic_id, COUNT(*) AS count + def self.update_views_count_for(period) + sql = "SELECT topic_id, COUNT(*) AS count FROM topic_views WHERE viewed_at >= :from GROUP BY topic_id" - TopTopic.update_top_topics(period, "views", sql) - end + TopTopic.update_top_topics(period, "views", sql) + end - def self.update_likes_count_for(period) - sql = "SELECT topic_id, GREATEST(SUM(like_count), 1) AS count + def self.update_likes_count_for(period) + sql = "SELECT topic_id, GREATEST(SUM(like_count), 1) AS count FROM posts WHERE created_at >= :from AND deleted_at IS NULL @@ -112,11 +111,11 @@ class TopTopic < ActiveRecord::Base AND post_type = #{Post.types[:regular]} GROUP BY topic_id" - TopTopic.update_top_topics(period, "likes", sql) - end + TopTopic.update_top_topics(period, "likes", sql) + end - def self.compute_top_score_for(period) - sql = <<-SQL + def self.compute_top_score_for(period) + sql = <<-SQL WITH top AS ( SELECT CASE WHEN topics.created_at < :from THEN 0 @@ -131,29 +130,29 @@ class TopTopic < ActiveRecord::Base FROM top WHERE top_topics.topic_id = top.topic_id AND #{period}_score <> top.score - SQL + SQL - exec_sql(sql, from: start_of(period)) + exec_sql(sql, from: start_of(period)) + end + + def self.start_of(period) + case period + when :yearly then 1.year.ago + when :monthly then 1.month.ago + when :weekly then 1.week.ago + when :daily then 1.day.ago end + end - def self.start_of(period) - case period - when :yearly then 1.year.ago - when :monthly then 1.month.ago - when :weekly then 1.week.ago - when :daily then 1.day.ago - end - end - - def self.update_top_topics(period, sort, inner_join) - exec_sql("UPDATE top_topics + def self.update_top_topics(period, sort, inner_join) + exec_sql("UPDATE top_topics SET #{period}_#{sort}_count = c.count FROM top_topics tt INNER JOIN (#{inner_join}) c ON tt.topic_id = c.topic_id WHERE tt.topic_id = top_topics.topic_id AND tt.#{period}_#{sort}_count <> c.count", - from: start_of(period)) - end + from: start_of(period)) + end end diff --git a/app/models/trust_level_setting.rb b/app/models/trust_level_setting.rb index bb777485d..54bcd3e04 100644 --- a/app/models/trust_level_setting.rb +++ b/app/models/trust_level_setting.rb @@ -10,8 +10,6 @@ class TrustLevelSetting < EnumSiteSetting @values ||= valid_values.map {|x| {name: x.to_s, value: x} } end - private - def self.valid_values TrustLevel.levels.values.sort end diff --git a/app/models/user_action.rb b/app/models/user_action.rb index 4574a5875..4280224bf 100644 --- a/app/models/user_action.rb +++ b/app/models/user_action.rb @@ -271,8 +271,6 @@ SQL self.synchronize_starred end - protected - def self.update_like_count(user_id, action_type, delta) if action_type == LIKE UserStat.where(user_id: user_id).update_all("likes_given = likes_given + #{delta.to_i}")