clean up mysqlism
This commit is contained in:
parent
ee9ac76ba9
commit
ee42f2f308
|
@ -8,7 +8,7 @@ module TrafficHelper
|
|||
|
||||
def self.traffic_range
|
||||
div = PERIOD_LENGTH * 60
|
||||
start_at = 'now() - interval 90 day'
|
||||
start_at = 90.days.ago
|
||||
result = ActiveRecord::Base.connection.execute <<-SQL
|
||||
select
|
||||
min(activity) as low,
|
||||
|
@ -19,9 +19,9 @@ module TrafficHelper
|
|||
-- s.period,
|
||||
v.n_votes + (c.n_comments * 10) + (s.n_stories * 20) AS activity
|
||||
from
|
||||
(SELECT count(1) AS n_votes, floor(UNIX_TIMESTAMP(updated_at)/#{div}) AS period FROM votes WHERE updated_at >= #{start_at} GROUP BY period) v,
|
||||
(SELECT count(1) AS n_comments, floor(UNIX_TIMESTAMP(created_at)/#{div}) AS period FROM comments WHERE created_at >= #{start_at} GROUP BY period) c,
|
||||
(SELECT count(1) AS n_stories, floor(UNIX_TIMESTAMP(created_at)/#{div}) AS period FROM stories WHERE created_at >= #{start_at} GROUP BY period) s
|
||||
(SELECT count(1) AS n_votes, floor(UNIX_TIMESTAMP(updated_at)/#{div}) AS period FROM votes WHERE updated_at >= "#{start_at}" GROUP BY period) v,
|
||||
(SELECT count(1) AS n_comments, floor(UNIX_TIMESTAMP(created_at)/#{div}) AS period FROM comments WHERE created_at >= "#{start_at}" GROUP BY period) c,
|
||||
(SELECT count(1) AS n_stories, floor(UNIX_TIMESTAMP(created_at)/#{div}) AS period FROM stories WHERE created_at >= "#{start_at}" GROUP BY period) s
|
||||
where
|
||||
s.period = c.period and
|
||||
s.period = v.period) act;
|
||||
|
@ -41,12 +41,12 @@ module TrafficHelper
|
|||
end
|
||||
|
||||
def self.current_activity
|
||||
start_at = "now() - interval #{PERIOD_LENGTH} minute"
|
||||
start_at = 15.minutes.ago
|
||||
result = ActiveRecord::Base.connection.execute <<-SQL
|
||||
select
|
||||
(SELECT count(1) AS n_votes FROM votes WHERE updated_at >= #{start_at}) +
|
||||
(SELECT count(1) AS n_comment FROM comments WHERE created_at >= #{start_at}) * 10 +
|
||||
(SELECT count(1) AS n_stories FROM stories WHERE created_at >= #{start_at}) * 20
|
||||
(SELECT count(1) AS n_votes FROM votes WHERE updated_at >= "#{start_at}") +
|
||||
(SELECT count(1) AS n_comment FROM comments WHERE created_at >= "#{start_at}") * 10 +
|
||||
(SELECT count(1) AS n_stories FROM stories WHERE created_at >= "#{start_at}") * 20
|
||||
SQL
|
||||
result.to_a.first.first
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue