don't include submissions in recent_stream_items

dashboards don't show these, and existing ones can be a little crazy if
they have lots of submission comments

also change cache key so these get regenerated

test plan:
1. dashboards should work
2. stream item api should work
3. specs should pass

Change-Id: I245f4464189a507f0e1a8c9dc1c4c1e9fd4b7566
Reviewed-on: https://gerrit.instructure.com/16502
Tested-by: Jenkins <jenkins@instructure.com>
Reviewed-by: Cody Cutrer <cody@instructure.com>
QA-Review: Cam Theriault <cam@instructure.com>
This commit is contained in:
Jon Jensen 2013-01-03 12:44:41 -07:00
parent 0ede7d45d5
commit b88e8b95bc
3 changed files with 20 additions and 2 deletions

View File

@ -1875,6 +1875,7 @@ class User < ActiveRecord::Base
instances
end
# NOTE: excludes submission stream items
def cached_recent_stream_items(opts={})
expires_in = 1.day
@ -1896,6 +1897,7 @@ class User < ActiveRecord::Base
end
end
# NOTE: excludes submission stream items
def recent_stream_items(opts={})
self.shard.activate do
ActiveRecord::Base::ConnectionSpecification.with_environment(:slave) do
@ -1905,7 +1907,9 @@ class User < ActiveRecord::Base
})
visible_instances.map do |sii|
si = sii.stream_item
si.data.write_attribute(:unread, sii.unread?) if si.present?
next unless si.present?
next if si.asset_type == 'Submission'
si.data.write_attribute(:unread, sii.unread?)
si
end.compact
end

View File

@ -44,7 +44,7 @@ class StreamItemCache < ActiveRecord::Observer
# Generate a cache key for User#recent_stream_items
def self.recent_stream_items_key(user, context_type = nil, context_id = nil)
user_id = (user.is_a?(User) ? user.id : user)
['recent_stream_items2', user_id, context_stream_item_key(context_type, context_id)].cache_key
['recent_stream_items3', user_id, context_stream_item_key(context_type, context_id)].cache_key
end
# Returns a cached cache key for the context with the time so all

View File

@ -157,6 +157,20 @@ describe User do
@user.recent_stream_items.size.should == 0
end
describe "#recent_stream_items" do
it "should skip submission stream items" do
course_with_teacher(:active_all => true)
course_with_student(:active_all => true, :course => @course)
assignment = @course.assignments.create!(:title => "some assignment", :submission_types => ['online_text_entry'])
sub = assignment.submit_homework @student, :submission_type => "online_text_entry", :body => "submission"
sub.add_comment :author => @teacher, :comment => "lol"
item = StreamItem.last
item.asset.should == sub
@student.visible_stream_item_instances.map(&:stream_item).should include item
@student.recent_stream_items.should_not include item
end
end
describe "#cached_recent_stream_items" do
before(:each) do
@contexts = []