invalidate user's cached groups on membership update
fixes CNVS-5256 test plan - as a teacher, add a user to a group - wait 15 minutes or clear the "Courses & Groups" cache entry - as the user, ensure that the new group shows up in the "Courses & Groups" menu - as the teacher, remove the user from the group - wait 15 minutes or clear the "Courses & Groups" cache entry - as the user, ensure that the new group does not show up in the "Courses & Groups" menu Change-Id: I091775f50783e0f9bb99a4adbc3e726a7f78be89 Reviewed-on: https://gerrit.instructure.com/45603 Reviewed-by: Andrew Butterfield <abutterfield@instructure.com> Tested-by: Jenkins <jenkins@instructure.com> QA-Review: Derek Hansen <dhansen@instructure.com> Product-Review: Joel Hough <joel@instructure.com>
This commit is contained in:
parent
9d0efa81ef
commit
7ae763642c
|
@ -40,8 +40,10 @@ class GroupMembership < ActiveRecord::Base
|
|||
after_save :touch_groups
|
||||
after_save :update_cached_due_dates
|
||||
after_save :update_group_leadership
|
||||
after_save :invalidate_user_membership_cache
|
||||
after_destroy :touch_groups
|
||||
after_destroy :update_group_leadership
|
||||
after_destroy :invalidate_user_membership_cache
|
||||
|
||||
has_a_broadcast_policy
|
||||
|
||||
|
@ -185,6 +187,10 @@ class GroupMembership < ActiveRecord::Base
|
|||
enrollments.any?{ |e| e.user == self.user && e.course == self.group.context })
|
||||
end
|
||||
|
||||
def invalidate_user_membership_cache
|
||||
Rails.cache.delete(self.user.group_membership_key)
|
||||
end
|
||||
|
||||
alias_method :destroy!, :destroy
|
||||
def destroy
|
||||
self.workflow_state = 'deleted'
|
||||
|
|
|
@ -1717,9 +1717,13 @@ class User < ActiveRecord::Base
|
|||
end
|
||||
end
|
||||
|
||||
def group_membership_key
|
||||
[self, 'current_group_memberships', ApplicationController.region].cache_key
|
||||
end
|
||||
|
||||
def cached_current_group_memberships
|
||||
self.shard.activate do
|
||||
@cached_current_group_memberships = Rails.cache.fetch([self, 'current_group_memberships', ApplicationController.region].cache_key) do
|
||||
@cached_current_group_memberships = Rails.cache.fetch(group_membership_key) do
|
||||
self.current_group_memberships.shard(self.in_region_associated_shards).to_a
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue