mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-12-17 19:12:37 -05:00
removed usless access modifiers specified in models
This commit is contained in:
parent
1a2070b4d9
commit
9d11ccc42e
13 changed files with 61 additions and 87 deletions
|
@ -194,14 +194,13 @@ class AdminDashboardData
|
||||||
I18n.t(i18n_key)
|
I18n.t(i18n_key)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.report_access_password_removal
|
def self.report_access_password_removal
|
||||||
$redis.setex access_password_removal_key, 172_800, 'dashboard.access_password_removal'
|
$redis.setex access_password_removal_key, 172_800, 'dashboard.access_password_removal'
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
def self.access_password_removal_key
|
||||||
|
'dash-data:access_password_removal'
|
||||||
def self.access_password_removal_key
|
end
|
||||||
'dash-data:access_password_removal'
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -35,14 +35,13 @@ class CategoryFeaturedTopic < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
def self.fake_admin
|
||||||
def self.fake_admin
|
# fake an admin
|
||||||
# fake an admin
|
admin = User.new
|
||||||
admin = User.new
|
admin.admin = true
|
||||||
admin.admin = true
|
admin.id = -1
|
||||||
admin.id = -1
|
admin
|
||||||
admin
|
end
|
||||||
end
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -60,8 +60,6 @@ class CategoryUser < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
|
||||||
|
|
||||||
def self.apply_default_to_topic(topic, level, reason)
|
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
|
# 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 = <<SQL
|
sql = <<SQL
|
||||||
|
|
|
@ -27,8 +27,6 @@ class Draft < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
protected
|
|
||||||
|
|
||||||
def self.find_draft(user, key)
|
def self.find_draft(user, key)
|
||||||
if user.is_a?(User)
|
if user.is_a?(User)
|
||||||
find_by(user_id: user.id, draft_key: key)
|
find_by(user_id: user.id, draft_key: key)
|
||||||
|
|
|
@ -85,8 +85,6 @@ class ErrorLog
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
|
||||||
|
|
||||||
def self.sanitize_backtrace(trace)
|
def self.sanitize_backtrace(trace)
|
||||||
re = Regexp.new(/^#{Regexp.escape(Rails.root.to_s)}/)
|
re = Regexp.new(/^#{Regexp.escape(Rails.root.to_s)}/)
|
||||||
trace.map { |line| Pathname.new(line.gsub(re, "[RAILS_ROOT]")).cleanpath.to_s }
|
trace.map { |line| Pathname.new(line.gsub(re, "[RAILS_ROOT]")).cleanpath.to_s }
|
||||||
|
|
|
@ -80,8 +80,6 @@ class GlobalSetting
|
||||||
@data.keys
|
@data.keys
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
private
|
|
||||||
def self.parse(file)
|
def self.parse(file)
|
||||||
provider = self.new(file)
|
provider = self.new(file)
|
||||||
provider.read
|
provider.read
|
||||||
|
|
|
@ -12,9 +12,6 @@ class LocaleSiteSetting < EnumSiteSetting
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
private
|
|
||||||
|
|
||||||
@lock = Mutex.new
|
@lock = Mutex.new
|
||||||
|
|
||||||
def self.supported_locales
|
def self.supported_locales
|
||||||
|
|
|
@ -26,10 +26,6 @@ class PluginStore
|
||||||
PluginStoreRow.where(plugin_name: plugin_name, key: key).destroy_all
|
PluginStoreRow.where(plugin_name: plugin_name, key: key).destroy_all
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
protected
|
|
||||||
|
|
||||||
|
|
||||||
def self.determine_type(value)
|
def self.determine_type(value)
|
||||||
value.is_a?(Hash) || value.is_a?(Array) ? "JSON" : value.class.to_s
|
value.is_a?(Hash) || value.is_a?(Array) ? "JSON" : value.class.to_s
|
||||||
end
|
end
|
||||||
|
|
|
@ -431,8 +431,6 @@ class PostAction < ActiveRecord::Base
|
||||||
PostActionType.types[post_action.post_action_type_id]
|
PostActionType.types[post_action.post_action_type_id]
|
||||||
end
|
end
|
||||||
|
|
||||||
protected
|
|
||||||
|
|
||||||
def self.target_moderators
|
def self.target_moderators
|
||||||
Group[:moderators].name
|
Group[:moderators].name
|
||||||
end
|
end
|
||||||
|
|
|
@ -9,8 +9,6 @@ class S3RegionSiteSetting < EnumSiteSetting
|
||||||
@values ||= valid_values.sort.map {|x| {name: x, value: x} }
|
@values ||= valid_values.sort.map {|x| {name: x, value: x} }
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
|
||||||
|
|
||||||
def self.valid_values
|
def self.valid_values
|
||||||
[ '',
|
[ '',
|
||||||
'us-east-1',
|
'us-east-1',
|
||||||
|
|
|
@ -28,25 +28,24 @@ class TopTopic < ActiveRecord::Base
|
||||||
TopTopic.refresh_older!
|
TopTopic.refresh_older!
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
|
||||||
|
|
||||||
def self.periods
|
def self.periods
|
||||||
@@periods ||= [:yearly, :monthly, :weekly, :daily].freeze
|
@@periods ||= [:yearly, :monthly, :weekly, :daily].freeze
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.sort_orders
|
||||||
|
@@sort_orders ||= [:posts, :views, :likes].freeze
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.update_counts_and_compute_scores_for(period)
|
||||||
|
TopTopic.sort_orders.each do |sort|
|
||||||
|
TopTopic.send("update_#{sort}_count_for", period)
|
||||||
end
|
end
|
||||||
|
TopTopic.compute_top_score_for(period)
|
||||||
|
end
|
||||||
|
|
||||||
def self.sort_orders
|
def self.remove_invisible_topics
|
||||||
@@sort_orders ||= [:posts, :views, :likes].freeze
|
exec_sql("WITH category_definition_topic_ids AS (
|
||||||
end
|
|
||||||
|
|
||||||
def self.update_counts_and_compute_scores_for(period)
|
|
||||||
TopTopic.sort_orders.each do |sort|
|
|
||||||
TopTopic.send("update_#{sort}_count_for", period)
|
|
||||||
end
|
|
||||||
TopTopic.compute_top_score_for(period)
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.remove_invisible_topics
|
|
||||||
exec_sql("WITH category_definition_topic_ids AS (
|
|
||||||
SELECT COALESCE(topic_id, 0) AS id FROM categories
|
SELECT COALESCE(topic_id, 0) AS id FROM categories
|
||||||
), invisible_topic_ids AS (
|
), invisible_topic_ids AS (
|
||||||
SELECT id
|
SELECT id
|
||||||
|
@ -59,11 +58,11 @@ class TopTopic < ActiveRecord::Base
|
||||||
)
|
)
|
||||||
DELETE FROM top_topics
|
DELETE FROM top_topics
|
||||||
WHERE topic_id IN (SELECT id FROM invisible_topic_ids)",
|
WHERE topic_id IN (SELECT id FROM invisible_topic_ids)",
|
||||||
private_message: Archetype::private_message)
|
private_message: Archetype::private_message)
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.add_new_visible_topics
|
def self.add_new_visible_topics
|
||||||
exec_sql("WITH category_definition_topic_ids AS (
|
exec_sql("WITH category_definition_topic_ids AS (
|
||||||
SELECT COALESCE(topic_id, 0) AS id FROM categories
|
SELECT COALESCE(topic_id, 0) AS id FROM categories
|
||||||
), visible_topics AS (
|
), visible_topics AS (
|
||||||
SELECT t.id
|
SELECT t.id
|
||||||
|
@ -78,11 +77,11 @@ class TopTopic < ActiveRecord::Base
|
||||||
)
|
)
|
||||||
INSERT INTO top_topics (topic_id)
|
INSERT INTO top_topics (topic_id)
|
||||||
SELECT id FROM visible_topics",
|
SELECT id FROM visible_topics",
|
||||||
private_message: Archetype::private_message)
|
private_message: Archetype::private_message)
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.update_posts_count_for(period)
|
def self.update_posts_count_for(period)
|
||||||
sql = "SELECT topic_id, GREATEST(COUNT(*), 1) AS count
|
sql = "SELECT topic_id, GREATEST(COUNT(*), 1) AS count
|
||||||
FROM posts
|
FROM posts
|
||||||
WHERE created_at >= :from
|
WHERE created_at >= :from
|
||||||
AND deleted_at IS NULL
|
AND deleted_at IS NULL
|
||||||
|
@ -91,20 +90,20 @@ class TopTopic < ActiveRecord::Base
|
||||||
AND user_id <> #{Discourse.system_user.id}
|
AND user_id <> #{Discourse.system_user.id}
|
||||||
GROUP BY topic_id"
|
GROUP BY topic_id"
|
||||||
|
|
||||||
TopTopic.update_top_topics(period, "posts", sql)
|
TopTopic.update_top_topics(period, "posts", sql)
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.update_views_count_for(period)
|
def self.update_views_count_for(period)
|
||||||
sql = "SELECT topic_id, COUNT(*) AS count
|
sql = "SELECT topic_id, COUNT(*) AS count
|
||||||
FROM topic_views
|
FROM topic_views
|
||||||
WHERE viewed_at >= :from
|
WHERE viewed_at >= :from
|
||||||
GROUP BY topic_id"
|
GROUP BY topic_id"
|
||||||
|
|
||||||
TopTopic.update_top_topics(period, "views", sql)
|
TopTopic.update_top_topics(period, "views", sql)
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.update_likes_count_for(period)
|
def self.update_likes_count_for(period)
|
||||||
sql = "SELECT topic_id, GREATEST(SUM(like_count), 1) AS count
|
sql = "SELECT topic_id, GREATEST(SUM(like_count), 1) AS count
|
||||||
FROM posts
|
FROM posts
|
||||||
WHERE created_at >= :from
|
WHERE created_at >= :from
|
||||||
AND deleted_at IS NULL
|
AND deleted_at IS NULL
|
||||||
|
@ -112,11 +111,11 @@ class TopTopic < ActiveRecord::Base
|
||||||
AND post_type = #{Post.types[:regular]}
|
AND post_type = #{Post.types[:regular]}
|
||||||
GROUP BY topic_id"
|
GROUP BY topic_id"
|
||||||
|
|
||||||
TopTopic.update_top_topics(period, "likes", sql)
|
TopTopic.update_top_topics(period, "likes", sql)
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.compute_top_score_for(period)
|
def self.compute_top_score_for(period)
|
||||||
sql = <<-SQL
|
sql = <<-SQL
|
||||||
WITH top AS (
|
WITH top AS (
|
||||||
SELECT CASE
|
SELECT CASE
|
||||||
WHEN topics.created_at < :from THEN 0
|
WHEN topics.created_at < :from THEN 0
|
||||||
|
@ -131,29 +130,29 @@ class TopTopic < ActiveRecord::Base
|
||||||
FROM top
|
FROM top
|
||||||
WHERE top_topics.topic_id = top.topic_id
|
WHERE top_topics.topic_id = top.topic_id
|
||||||
AND #{period}_score <> top.score
|
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
|
||||||
|
end
|
||||||
|
|
||||||
def self.start_of(period)
|
def self.update_top_topics(period, sort, inner_join)
|
||||||
case period
|
exec_sql("UPDATE top_topics
|
||||||
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
|
|
||||||
SET #{period}_#{sort}_count = c.count
|
SET #{period}_#{sort}_count = c.count
|
||||||
FROM top_topics tt
|
FROM top_topics tt
|
||||||
INNER JOIN (#{inner_join}) c ON tt.topic_id = c.topic_id
|
INNER JOIN (#{inner_join}) c ON tt.topic_id = c.topic_id
|
||||||
WHERE tt.topic_id = top_topics.topic_id
|
WHERE tt.topic_id = top_topics.topic_id
|
||||||
AND tt.#{period}_#{sort}_count <> c.count",
|
AND tt.#{period}_#{sort}_count <> c.count",
|
||||||
from: start_of(period))
|
from: start_of(period))
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -10,8 +10,6 @@ class TrustLevelSetting < EnumSiteSetting
|
||||||
@values ||= valid_values.map {|x| {name: x.to_s, value: x} }
|
@values ||= valid_values.map {|x| {name: x.to_s, value: x} }
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
|
||||||
|
|
||||||
def self.valid_values
|
def self.valid_values
|
||||||
TrustLevel.levels.values.sort
|
TrustLevel.levels.values.sort
|
||||||
end
|
end
|
||||||
|
|
|
@ -271,8 +271,6 @@ SQL
|
||||||
self.synchronize_starred
|
self.synchronize_starred
|
||||||
end
|
end
|
||||||
|
|
||||||
protected
|
|
||||||
|
|
||||||
def self.update_like_count(user_id, action_type, delta)
|
def self.update_like_count(user_id, action_type, delta)
|
||||||
if action_type == LIKE
|
if action_type == LIKE
|
||||||
UserStat.where(user_id: user_id).update_all("likes_given = likes_given + #{delta.to_i}")
|
UserStat.where(user_id: user_id).update_all("likes_given = likes_given + #{delta.to_i}")
|
||||||
|
|
Loading…
Reference in a new issue