mirror of
https://github.com/zulip/zulip.git
synced 2025-11-01 20:44:04 +00:00
cache_helpers: Fill the narrow-user cache as well.
This commit is contained in:
committed by
Tim Abbott
parent
9ff68a45c5
commit
11c32dcfb2
@@ -20,12 +20,13 @@ from zerver.lib.cache import (
|
||||
get_remote_cache_time,
|
||||
user_profile_by_api_key_cache_key,
|
||||
user_profile_by_id_cache_key,
|
||||
user_profile_narrow_by_id_cache_key,
|
||||
)
|
||||
from zerver.lib.safe_session_cached_db import SessionStore
|
||||
from zerver.lib.sessions import session_engine
|
||||
from zerver.models import Client, UserProfile
|
||||
from zerver.models.clients import get_client_cache_key
|
||||
from zerver.models.users import base_get_user_queryset
|
||||
from zerver.models.users import base_get_user_narrow_queryset, base_get_user_queryset
|
||||
|
||||
|
||||
def get_users() -> QuerySet[UserProfile]:
|
||||
@@ -41,6 +42,18 @@ def user_cache_items(
|
||||
items_for_remote_cache[user_profile_by_id_cache_key(user_profile.id)] = (user_profile,)
|
||||
|
||||
|
||||
def get_narrow_users() -> QuerySet[UserProfile]:
|
||||
return base_get_user_narrow_queryset().filter(
|
||||
long_term_idle=False, realm__in=get_active_realm_ids()
|
||||
)
|
||||
|
||||
|
||||
def user_narrow_cache_items(
|
||||
items_for_remote_cache: dict[str, tuple[UserProfile]], user_profile: UserProfile
|
||||
) -> None:
|
||||
items_for_remote_cache[user_profile_narrow_by_id_cache_key(user_profile.id)] = (user_profile,)
|
||||
|
||||
|
||||
def client_cache_items(items_for_remote_cache: dict[str, tuple[Client]], client: Client) -> None:
|
||||
items_for_remote_cache[get_client_cache_key(client.name)] = (client,)
|
||||
|
||||
@@ -90,6 +103,7 @@ cache_fillers: dict[
|
||||
str, tuple[Callable[[], Iterable[Any]], Callable[[dict[str, Any], Any], None], int, int]
|
||||
] = {
|
||||
"user": (get_users, user_cache_items, 3600 * 24 * 7, 10000),
|
||||
"user_narrow": (get_narrow_users, user_narrow_cache_items, 3600 * 24 * 7, 10000),
|
||||
"client": (
|
||||
Client.objects.all,
|
||||
client_cache_items,
|
||||
|
||||
@@ -956,23 +956,23 @@ def get_user_profile_by_id(user_profile_id: int) -> UserProfile:
|
||||
return base_get_user_queryset().get(id=user_profile_id)
|
||||
|
||||
|
||||
def base_get_user_narrow_queryset() -> QuerySet[UserProfile]:
|
||||
return UserProfile.objects.select_related("realm").only(
|
||||
"id",
|
||||
"bot_type",
|
||||
"is_active",
|
||||
"presence_enabled",
|
||||
"rate_limits",
|
||||
"role",
|
||||
"recipient_id",
|
||||
"realm__string_id",
|
||||
"realm__deactivated",
|
||||
)
|
||||
|
||||
|
||||
@cache_with_key(user_profile_narrow_by_id_cache_key, timeout=3600 * 24 * 7)
|
||||
def get_user_profile_narrow_by_id(user_profile_id: int) -> UserProfile:
|
||||
return (
|
||||
UserProfile.objects.select_related("realm")
|
||||
.only(
|
||||
"id",
|
||||
"bot_type",
|
||||
"is_active",
|
||||
"presence_enabled",
|
||||
"rate_limits",
|
||||
"role",
|
||||
"recipient_id",
|
||||
"realm__string_id",
|
||||
"realm__deactivated",
|
||||
)
|
||||
.get(id=user_profile_id)
|
||||
)
|
||||
return base_get_user_narrow_queryset().get(id=user_profile_id)
|
||||
|
||||
|
||||
def get_user_profile_by_email(email: str) -> UserProfile:
|
||||
|
||||
Reference in New Issue
Block a user