settings: Refetch realm and user profile objects.

This is a temporary solution to make sure stale objects from
cache are not used when previous request updated multiple settings.
This commit is contained in:
Sahil Batra 2024-07-17 00:30:59 +05:30 committed by Tim Abbott
parent 5b1326668f
commit a0efc0ee76
2 changed files with 16 additions and 1 deletions

View File

@ -177,7 +177,14 @@ def update_realm(
Json[int] | None, ApiParamConfig("can_access_all_users_group") Json[int] | None, ApiParamConfig("can_access_all_users_group")
] = None, ] = None,
) -> HttpResponse: ) -> HttpResponse:
realm = user_profile.realm # Realm object is being refetched here to make sure that we
# do not use stale object from cache which can happen when a
# previous request tried updating multiple settings in a single
# request.
#
# TODO: Change the cache flushing strategy to make sure cache
# does not contain stale objects.
realm = Realm.objects.get(id=user_profile.realm_id)
# Additional validation/error checking beyond types go here, so # Additional validation/error checking beyond types go here, so
# the entire request can succeed or fail atomically. # the entire request can succeed or fail atomically.

View File

@ -305,6 +305,14 @@ def json_change_settings(
), ),
web_navigate_to_sent_message: bool | None = REQ(json_validator=check_bool, default=None), web_navigate_to_sent_message: bool | None = REQ(json_validator=check_bool, default=None),
) -> HttpResponse: ) -> HttpResponse:
# UserProfile object is being refetched here to make sure that we
# do not use stale object from cache which can happen when a
# previous request tried updating multiple settings in a single
# request.
#
# TODO: Change the cache flushing strategy to make sure cache
# does not contain stale objects.
user_profile = UserProfile.objects.get(id=user_profile.id)
if ( if (
default_language is not None default_language is not None
or notification_sound is not None or notification_sound is not None