clear cached context short names after update

test plan:
* add a rubric to a course
* update the course's course code
* use the "find rubric" to add an existing
 rubric to an assignment
* the course code listed on the left side
 should match the new course code

closes #OUT-1781

Change-Id: Iebc77716ecfef90ae9e099367c2305314dbf265e
Reviewed-on: https://gerrit.instructure.com/136576
Tested-by: Jenkins
Reviewed-by: Jeremy Stanley <jeremy@instructure.com>
QA-Review: Andrew Porter <hporter-c@instructure.com>
Product-Review: James Williams  <jamesw@instructure.com>
This commit is contained in:
James Williams 2017-12-28 09:41:08 -07:00
parent cd73f4bd74
commit 45ddbd2d0e
7 changed files with 32 additions and 1 deletions

View File

@ -108,6 +108,8 @@ class Account < ActiveRecord::Base
after_save :invalidate_caches_if_changed
after_update :clear_special_account_cache_if_special
after_update :clear_cached_short_name, :if => :name_changed?
after_create :create_default_objects
serialize :settings, Hash

View File

@ -54,6 +54,12 @@ module Context
Eportfolio: :Eportfolio
}.freeze
def clear_cached_short_name
self.class.connection.after_transaction_commit do
Rails.cache.delete(['short_name_lookup', self.asset_string].cache_key)
end
end
def add_aggregate_entries(entries, feed)
entries.each do |entry|
user = entry.user || feed.user

View File

@ -209,6 +209,8 @@ class Course < ActiveRecord::Base
after_save :set_self_enrollment_code
after_commit :update_cached_due_dates
after_update :clear_cached_short_name, :if => :course_code_changed?
before_update :handle_syllabus_changes_for_master_migration
before_save :touch_root_folder_if_necessary

View File

@ -71,6 +71,8 @@ class Group < ActiveRecord::Base
after_create :refresh_group_discussion_topics
after_update :clear_cached_short_name, :if => :name_changed?
delegate :time_zone, :to => :context
include StickySisFields

View File

@ -207,7 +207,7 @@ class StreamItem < ActiveRecord::Base
raise "Unexpected stream item type: #{object.class}"
end
if self.context_type
res['context_short_name'] = Rails.cache.fetch(['short_name_lookup', self.context_type, self.context_id].cache_key) do
res['context_short_name'] = Rails.cache.fetch(['short_name_lookup', "#{self.context_type.underscore}_#{self.context_id}"].cache_key) do
self.context.short_name rescue ''
end
end

View File

@ -36,6 +36,8 @@ class User < ActiveRecord::Base
before_save :infer_defaults
after_create :set_default_feature_flags
after_update :clear_cached_short_name, if: -> (user) {user.short_name_changed? || (user.read_attribute(:short_name).nil? && user.name_changed?)}
serialize :preferences
include TimeZoneHelper
time_zone_attribute :time_zone

View File

@ -54,6 +54,23 @@ describe StreamItem do
expect(de.reload.discussion_topic_id).not_to be_nil
end
it "uses new context short name" do
user_factory
context = Course.create!(:course_code => "some name")
enable_cache do
dt1 = DiscussionTopic.create!(:context => context)
dt1.generate_stream_items([@user])
si1 = StreamItem.where(:asset_id => dt1.id).first
expect(si1.data.context_short_name).to eq "some name"
context.update_attribute(:course_code, "some other name")
dt2 = DiscussionTopic.create!(:context => context)
dt2.generate_stream_items([@user])
si2 = StreamItem.where(:asset_id => dt2.id).first
expect(si2.data.context_short_name).to eq "some other name"
end
end
describe "destroy_stream_items_using_setting" do
it "should have a default ttl" do
si1 = StreamItem.create! { |si| si.asset_type = 'Message'; si.data = { notification_id: nil } }