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:
parent
cd73f4bd74
commit
45ddbd2d0e
|
@ -108,6 +108,8 @@ class Account < ActiveRecord::Base
|
||||||
after_save :invalidate_caches_if_changed
|
after_save :invalidate_caches_if_changed
|
||||||
after_update :clear_special_account_cache_if_special
|
after_update :clear_special_account_cache_if_special
|
||||||
|
|
||||||
|
after_update :clear_cached_short_name, :if => :name_changed?
|
||||||
|
|
||||||
after_create :create_default_objects
|
after_create :create_default_objects
|
||||||
|
|
||||||
serialize :settings, Hash
|
serialize :settings, Hash
|
||||||
|
|
|
@ -54,6 +54,12 @@ module Context
|
||||||
Eportfolio: :Eportfolio
|
Eportfolio: :Eportfolio
|
||||||
}.freeze
|
}.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)
|
def add_aggregate_entries(entries, feed)
|
||||||
entries.each do |entry|
|
entries.each do |entry|
|
||||||
user = entry.user || feed.user
|
user = entry.user || feed.user
|
||||||
|
|
|
@ -209,6 +209,8 @@ class Course < ActiveRecord::Base
|
||||||
after_save :set_self_enrollment_code
|
after_save :set_self_enrollment_code
|
||||||
after_commit :update_cached_due_dates
|
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_update :handle_syllabus_changes_for_master_migration
|
||||||
|
|
||||||
before_save :touch_root_folder_if_necessary
|
before_save :touch_root_folder_if_necessary
|
||||||
|
|
|
@ -71,6 +71,8 @@ class Group < ActiveRecord::Base
|
||||||
|
|
||||||
after_create :refresh_group_discussion_topics
|
after_create :refresh_group_discussion_topics
|
||||||
|
|
||||||
|
after_update :clear_cached_short_name, :if => :name_changed?
|
||||||
|
|
||||||
delegate :time_zone, :to => :context
|
delegate :time_zone, :to => :context
|
||||||
|
|
||||||
include StickySisFields
|
include StickySisFields
|
||||||
|
|
|
@ -207,7 +207,7 @@ class StreamItem < ActiveRecord::Base
|
||||||
raise "Unexpected stream item type: #{object.class}"
|
raise "Unexpected stream item type: #{object.class}"
|
||||||
end
|
end
|
||||||
if self.context_type
|
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 ''
|
self.context.short_name rescue ''
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -36,6 +36,8 @@ class User < ActiveRecord::Base
|
||||||
|
|
||||||
before_save :infer_defaults
|
before_save :infer_defaults
|
||||||
after_create :set_default_feature_flags
|
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
|
serialize :preferences
|
||||||
include TimeZoneHelper
|
include TimeZoneHelper
|
||||||
time_zone_attribute :time_zone
|
time_zone_attribute :time_zone
|
||||||
|
|
|
@ -54,6 +54,23 @@ describe StreamItem do
|
||||||
expect(de.reload.discussion_topic_id).not_to be_nil
|
expect(de.reload.discussion_topic_id).not_to be_nil
|
||||||
end
|
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
|
describe "destroy_stream_items_using_setting" do
|
||||||
it "should have a default ttl" do
|
it "should have a default ttl" do
|
||||||
si1 = StreamItem.create! { |si| si.asset_type = 'Message'; si.data = { notification_id: nil } }
|
si1 = StreamItem.create! { |si| si.asset_type = 'Message'; si.data = { notification_id: nil } }
|
||||||
|
|
Loading…
Reference in New Issue