Permalink
Browse files

GH#6 limit the number of show data points shown on the main page graph

  • Loading branch information...
1 parent 3dab7e7 commit da4c14e630cc1160e59e6f64b325c711dca51817 @tardate committed Jan 2, 2012
View
@@ -15,6 +15,7 @@ class Meme < ActiveRecord::Base
select("memes.name AS meme_name, shows.number as number, count(notes.id) as note_count").
joins(:shows).
where(Meme.arel_table[:id].in((meme_id ? meme_id : topn_arel))).
+ where(Show.arel_table[:id].in(Show.shows_for_trending_history_arel)).
group(:"memes.name", :"shows.number").
reorder('memes.name, shows.number')
}
View
@@ -31,6 +31,10 @@ def lastn_arel(limit = AppConstants.number_of_shows_for_trending)
s.project(s[:id]).
order(s[:number].desc).take(limit)
end
+ # Returns the arel fragment to get the show ids for the number_of_shows_for_trending_history
+ def shows_for_trending_history_arel
+ lastn_arel(AppConstants.number_of_shows_for_trending_history || 10)
+ end
end
STAT_CHART_TEMPLATE = {
View
@@ -7,6 +7,8 @@ development: &default
number_of_trending_memes: 5
# number of shows back to look to calculate trending stat
number_of_shows_for_trending: 6
+ # number of shows to display trending meme history
+ number_of_shows_for_trending_history: 16
production:
<<: *default
@@ -36,7 +36,7 @@ def load_show(number,reload=false)
show = Show.find_or_initialize_by_number(number)
if reload || show.new_record?
show.update_attributes!(show_loader.attributes)
- show.notes.destroy # we'll reload if they already exist
+ show.notes.destroy_all # we'll reload if they already exist
show_loader.show_notes.each do |show_note|
meme = Meme.factory(show_note[:meme_name])
note = Note.find_or_initialize_by_show_id_and_url(show.id,show_note[:url])
@@ -55,6 +55,12 @@
subject.last[:note_count].should eql("#{seed_limit}")
end
+ context "with trending history limit" do
+ let(:trending_history_limit) { AppConstants.number_of_shows_for_trending_history || 10 }
+ subject { Meme.stats_over_time }
+ its(:to_sql) { should include( %("shows"."id" IN (SELECT "shows"."id" FROM "shows" ORDER BY "shows"."number" DESC LIMIT #{trending_history_limit})) ) }
+ end
+
describe "#stat_over_time" do
let(:meme) { Meme.first }
subject { meme.stat_over_time }
@@ -45,6 +45,15 @@
its(:count) { should eql(limit) }
end
+ describe "##shows_for_trending_history_arel" do
+ let(:limit) { AppConstants.number_of_shows_for_trending_history }
+ before do
+ (limit * 2).times { Factory.create(:show) }
+ end
+ subject { Show.where(:id => Show.shows_for_trending_history_arel) }
+ its(:count) { should eql(limit) }
+ end
+
describe "#short_title" do
let(:expected) { "33 - #{published_date}" }
subject { resource }

0 comments on commit da4c14e

Please sign in to comment.