mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
make sure Category.topic_count is consistent with week/year stats
This commit is contained in:
parent
5bf3a0eaf3
commit
d50b5e1fd8
@ -61,11 +61,13 @@ class Category < ActiveRecord::Base
|
|||||||
.where("categories.topic_id <> topics.id")
|
.where("categories.topic_id <> topics.id")
|
||||||
.visible
|
.visible
|
||||||
|
|
||||||
|
topic_count = topics.to_sql
|
||||||
topics_year = topics.created_since(1.year.ago).to_sql
|
topics_year = topics.created_since(1.year.ago).to_sql
|
||||||
topics_month = topics.created_since(1.month.ago).to_sql
|
topics_month = topics.created_since(1.month.ago).to_sql
|
||||||
topics_week = topics.created_since(1.week.ago).to_sql
|
topics_week = topics.created_since(1.week.ago).to_sql
|
||||||
|
|
||||||
Category.update_all("topics_year = (#{topics_year}),
|
Category.update_all("topic_count = (#{topic_count}),
|
||||||
|
topics_year = (#{topics_year}),
|
||||||
topics_month = (#{topics_month}),
|
topics_month = (#{topics_month}),
|
||||||
topics_week = (#{topics_week})")
|
topics_week = (#{topics_week})")
|
||||||
end
|
end
|
||||||
|
@ -177,6 +177,10 @@ describe Category do
|
|||||||
it 'updates topics_year' do
|
it 'updates topics_year' do
|
||||||
@category.topics_year.should == 1
|
@category.topics_year.should == 1
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'updates topic_count' do
|
||||||
|
@category.topic_count.should == 1
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'with deleted topics' do
|
context 'with deleted topics' do
|
||||||
@ -198,6 +202,10 @@ describe Category do
|
|||||||
it 'does not count deleted topics for topics_year' do
|
it 'does not count deleted topics for topics_year' do
|
||||||
@category.topics_year.should == 0
|
@category.topics_year.should == 0
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'does not count deleted topics for topic_count' do
|
||||||
|
@category.topic_count.should == 0
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user