realms: Add caching to the get_seat_count calculation for upload limit.

For simiplicty's sake, we can avoid trying to do cache invalidation in
the variety of events that can cause the seat count to change - since
having an up to 1 day delay between users being added and the upload
limit going up is quite reasonable.
This commit is contained in:
Mateusz Mandera
2024-04-14 00:25:05 +02:00
committed by Tim Abbott
parent 066de96a86
commit 4a2a9176c2
3 changed files with 15 additions and 2 deletions

View File

@@ -847,11 +847,11 @@ class Realm(models.Model): # type: ignore[django-manager-missing] # django-stub
elif plan_type == Realm.PLAN_TYPE_STANDARD_FREE:
return Realm.UPLOAD_QUOTA_STANDARD_FREE
elif plan_type in [Realm.PLAN_TYPE_STANDARD, Realm.PLAN_TYPE_PLUS]:
from corporate.lib.stripe import get_seat_count
from corporate.lib.stripe import get_cached_seat_count
# Paying customers with few users should get a reasonable minimum quota.
return max(
get_seat_count(self) * settings.UPLOAD_QUOTA_PER_USER_GB,
get_cached_seat_count(self) * settings.UPLOAD_QUOTA_PER_USER_GB,
Realm.UPLOAD_QUOTA_STANDARD_FREE,
)
else: