From 0ea5daece879d30d97d1df2ece7facc54fb7e9f1 Mon Sep 17 00:00:00 2001 From: Sahil Batra Date: Wed, 17 Jul 2024 12:53:34 +0530 Subject: [PATCH] user_settings: Flush cache after commiting changes to DB. We should flush the cache after commiting changes to DB to make sure that the cache does not contain stale data when updating multiple settings in a single request. --- zerver/actions/user_settings.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/zerver/actions/user_settings.py b/zerver/actions/user_settings.py index 2e1a3a9fb2..334806d1d2 100644 --- a/zerver/actions/user_settings.py +++ b/zerver/actions/user_settings.py @@ -472,6 +472,8 @@ def do_change_user_setting( assert isinstance(setting_value, str) event["language_name"] = get_language_name(setting_value) + transaction.on_commit(lambda: flush_user_profile(sender=UserProfile, instance=user_profile)) + send_event_on_commit(user_profile.realm, event, [user_profile.id]) if setting_name in {"web_font_size_px", "web_line_height_percent"}: @@ -545,8 +547,6 @@ def do_change_user_setting( user_profile.email = get_display_email_address(user_profile) user_profile.save(update_fields=["email"]) - transaction.on_commit(lambda: flush_user_profile(sender=UserProfile, instance=user_profile)) - send_user_email_update_event(user_profile) notify_avatar_url_change(user_profile)