mirror of
https://github.com/zulip/zulip.git
synced 2025-11-17 20:41:46 +00:00
attachments: Refactor code for flushing used_upload_space cache.
Subsequent commits will add "on_delete=models.RESTRICT" relationships, which will result in the Attachment objects being deleted after Realm has been deleted from the database. In order to handle this, we update get_realm_used_upload_space_cache_key function to accept realm_id as parameter instead of realm object, so that the code for flushing the cache works even after the realm is deleted. This change is fine because eventually only realm_id is used by this function and there is no need of the complete realm object.
This commit is contained in:
@@ -498,8 +498,8 @@ def get_muting_users_cache_key(muted_user_id: int) -> str:
|
||||
return f"muting_users_list:{muted_user_id}"
|
||||
|
||||
|
||||
def get_realm_used_upload_space_cache_key(realm: "Realm") -> str:
|
||||
return f"realm_used_upload_space:{realm.id}"
|
||||
def get_realm_used_upload_space_cache_key(realm_id: int) -> str:
|
||||
return f"realm_used_upload_space:{realm_id}"
|
||||
|
||||
|
||||
def active_user_ids_cache_key(realm_id: int) -> str:
|
||||
@@ -699,7 +699,7 @@ def flush_used_upload_space_cache(
|
||||
attachment = instance
|
||||
|
||||
if created:
|
||||
cache_delete(get_realm_used_upload_space_cache_key(attachment.owner.realm))
|
||||
cache_delete(get_realm_used_upload_space_cache_key(attachment.owner.realm_id))
|
||||
|
||||
|
||||
def to_dict_cache_key_id(message_id: int) -> str:
|
||||
|
||||
Reference in New Issue
Block a user