mirror of
https://github.com/zulip/zulip.git
synced 2025-10-23 04:52:12 +00:00
cache: Log a warning when attempting to store a whole QuerySet.
As noted in the previous commit, this causes bloat in memcached, for no purpose. Log a warning when `cache_with_key` sees a QuerySet returned from the function it is decorating.
This commit is contained in:
committed by
Tim Abbott
parent
55c0e670d9
commit
c328de3372
@@ -26,6 +26,7 @@ from django.conf import settings
|
||||
from django.core.cache import caches
|
||||
from django.core.cache.backends.base import BaseCache
|
||||
from django.db.models import Q
|
||||
from django.db.models.query import QuerySet
|
||||
from django.http import HttpRequest
|
||||
from typing_extensions import ParamSpec
|
||||
|
||||
@@ -173,6 +174,12 @@ def cache_with_key(
|
||||
return val[0]
|
||||
|
||||
val = func(*args, **kwargs)
|
||||
if isinstance(val, QuerySet): # type: ignore[misc] # https://github.com/typeddjango/django-stubs/issues/704
|
||||
logging.warning(
|
||||
"cache_with_key attempted to store a full QuerySet object -- flattening using list()",
|
||||
stack_info=True,
|
||||
)
|
||||
val = list(val)
|
||||
|
||||
cache_set(key, val, cache_name=cache_name, timeout=timeout)
|
||||
|
||||
|
Reference in New Issue
Block a user