mirror of
https://github.com/zulip/zulip.git
synced 2025-11-06 23:13:25 +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:
@@ -950,7 +950,9 @@ class Realm(models.Model): # type: ignore[django-manager-missing] # django-stub
|
||||
|
||||
# `realm` instead of `self` here to make sure the parameters of the cache key
|
||||
# function matches the original method.
|
||||
@cache_with_key(get_realm_used_upload_space_cache_key, timeout=3600 * 24 * 7)
|
||||
@cache_with_key(
|
||||
lambda realm: get_realm_used_upload_space_cache_key(realm.id), timeout=3600 * 24 * 7
|
||||
)
|
||||
def currently_used_upload_space_bytes(realm) -> int: # noqa: N805
|
||||
used_space = Attachment.objects.filter(realm=realm).aggregate(Sum("size"))["size__sum"]
|
||||
if used_space is None:
|
||||
|
||||
Reference in New Issue
Block a user