Fix dashboard totals for topics, posts, and private messages
This commit is contained in:
parent
ab85d4a757
commit
eb212aec9b
|
@ -40,6 +40,8 @@ class Post < ActiveRecord::Base
|
||||||
|
|
||||||
scope :by_newest, order('created_at desc, id desc')
|
scope :by_newest, order('created_at desc, id desc')
|
||||||
scope :with_user, includes(:user)
|
scope :with_user, includes(:user)
|
||||||
|
scope :public_posts, lambda { joins(:topic).where('topics.archetype <> ?', [Archetype.private_message]) }
|
||||||
|
scope :private_posts, lambda { joins(:topic).where('topics.archetype = ?', Archetype.private_message) }
|
||||||
|
|
||||||
def self.hidden_reasons
|
def self.hidden_reasons
|
||||||
@hidden_reasons ||= Enum.new(:flag_threshold_reached, :flag_threshold_reached_again)
|
@hidden_reasons ||= Enum.new(:flag_threshold_reached, :flag_threshold_reached_again)
|
||||||
|
@ -391,10 +393,10 @@ class Post < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.public_posts_count_per_day(sinceDaysAgo=30)
|
def self.public_posts_count_per_day(sinceDaysAgo=30)
|
||||||
joins(:topic).where('topics.archetype <> ?', [Archetype.private_message]).where('posts.created_at > ?', sinceDaysAgo.days.ago).group('date(posts.created_at)').order('date(posts.created_at)').count
|
public_posts.where('posts.created_at > ?', sinceDaysAgo.days.ago).group('date(posts.created_at)').order('date(posts.created_at)').count
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.private_messages_count_per_day(sinceDaysAgo=30)
|
def self.private_messages_count_per_day(sinceDaysAgo=30)
|
||||||
joins(:topic).where('topics.archetype = ?', Archetype.private_message).where('posts.created_at > ?', sinceDaysAgo.days.ago).group('date(posts.created_at)').order('date(posts.created_at)').count
|
private_posts.where('posts.created_at > ?', sinceDaysAgo.days.ago).group('date(posts.created_at)').order('date(posts.created_at)').count
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -40,15 +40,21 @@ class Report
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.report_topics(report)
|
def self.report_topics(report)
|
||||||
report_about report, Topic, :listable_count_per_day
|
basic_report_about report, Topic, :listable_count_per_day
|
||||||
|
report.total = Topic.listable_topics.count
|
||||||
|
report.prev30Days = Topic.listable_topics.where('created_at > ? and created_at < ?', 60.days.ago, 30.days.ago).count
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.report_posts(report)
|
def self.report_posts(report)
|
||||||
report_about report, Post, :public_posts_count_per_day
|
basic_report_about report, Post, :public_posts_count_per_day
|
||||||
|
report.total = Post.public_posts.count
|
||||||
|
report.prev30Days = Post.public_posts.where('posts.created_at > ? and posts.created_at < ?', 60.days.ago, 30.days.ago).count
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.report_private_messages(report)
|
def self.report_private_messages(report)
|
||||||
report_about report, Post, :private_messages_count_per_day
|
basic_report_about report, Post, :private_messages_count_per_day
|
||||||
|
report.total = Post.private_posts.count
|
||||||
|
report.prev30Days = Post.private_posts.where('posts.created_at > ? and posts.created_at < ?', 60.days.ago, 30.days.ago).count
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.report_emails(report)
|
def self.report_emails(report)
|
||||||
|
|
|
@ -68,6 +68,7 @@ describe Report do
|
||||||
Fabricate(:topic, created_at: 1.hour.ago)
|
Fabricate(:topic, created_at: 1.hour.ago)
|
||||||
report = Report.find('topics')
|
report = Report.find('topics')
|
||||||
report.data[0][:y].should == 1
|
report.data[0][:y].should == 1
|
||||||
|
report.total.should == 1
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'post report should not include private messages' do
|
it 'post report should not include private messages' do
|
||||||
|
@ -75,6 +76,7 @@ describe Report do
|
||||||
Fabricate(:post)
|
Fabricate(:post)
|
||||||
report = Report.find('posts')
|
report = Report.find('posts')
|
||||||
report.data[0][:y].should == 1
|
report.data[0][:y].should == 1
|
||||||
|
report.total.should == 1
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'no private messages' do
|
context 'no private messages' do
|
||||||
|
@ -86,6 +88,7 @@ describe Report do
|
||||||
it 'returns an empty report' do
|
it 'returns an empty report' do
|
||||||
Fabricate(:post); Fabricate(:post)
|
Fabricate(:post); Fabricate(:post)
|
||||||
report.data.should be_blank
|
report.data.should be_blank
|
||||||
|
report.total.should == 0
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -100,6 +103,7 @@ describe Report do
|
||||||
it 'returns correct data' do
|
it 'returns correct data' do
|
||||||
report.data[0][:y].should == 1
|
report.data[0][:y].should == 1
|
||||||
report.data[1][:y].should == 2
|
report.data[1][:y].should == 2
|
||||||
|
report.total.should == 3
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'and some public posts' do
|
context 'and some public posts' do
|
||||||
|
@ -110,6 +114,7 @@ describe Report do
|
||||||
it 'returns correct data' do
|
it 'returns correct data' do
|
||||||
report.data[0][:y].should == 1
|
report.data[0][:y].should == 1
|
||||||
report.data[1][:y].should == 2
|
report.data[1][:y].should == 2
|
||||||
|
report.total.should == 3
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue