Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
decorator: Remove cachify in favor of lru_cache.
Zixuan James Li9d448e73d2c3
diff --git a/zerver/decorator.py b/zerver/decorator.pyindex eb13f08153f..934cb45bcbb 100644--- a/zerver/decorator.py+++ b/zerver/decorator.py@@ -4,7 +4,7 @@ import loggingimport urllibfrom functools import wrapsfrom io import BytesIO-from typing import Callable, Dict, Optional, Sequence, Set, Tuple, TypeVar, Union, cast, overload+from typing import Callable, Dict, Optional, Sequence, Set, TypeVar, Union, cast, overloadimport django_otpimport orjson@@ -70,20 +70,6 @@ webhook_anomalous_payloads_logger = logging.getLogger("zulip.zerver.webhooks.anoFuncT = TypeVar("FuncT", bound=Callable[..., object])-def cachify(method: FuncT) -> FuncT:- dct: Dict[Tuple[object, ...], object] = {}-- def cache_wrapper(*args: object) -> object:- tup = tuple(args)- if tup in dct:- return dct[tup]- result = method(*args)- dct[tup] = result- return result-- return cast(FuncT, cache_wrapper) # https://github.com/python/mypy/issues/1927--def update_user_activity(request: HttpRequest, user_profile: UserProfile, query: Optional[str]) -> None:diff --git a/zerver/lib/export.py b/zerver/lib/export.pyindex d0ca0916590..a49bbce9483 100644--- a/zerver/lib/export.py+++ b/zerver/lib/export.py@@ -13,6 +13,7 @@ import osimport shutilimport subprocessimport tempfile+from functools import lru_cachefrom typing import Any, Callable, Dict, List, Optional, Set, Tupleimport orjson@@ -28,7 +29,6 @@ from typing_extensions import TypedDictimport zerver.lib.uploadfrom analytics.models import RealmCount, StreamCount, UserCountfrom scripts.lib.zulip_tools import overwrite_symlink-from zerver.decorator import cachifyfrom zerver.lib.avatar_hash import user_avatar_path_from_idsfrom zerver.lib.pysa import mark_sanitizedfrom zerver.lib.upload import get_bucket@@ -2107,7 +2107,7 @@ def chunkify(lst: List[int], chunk_size: int) -> List[List[int]]:def export_messages_single_user(user_profile: UserProfile, *, output_dir: Path, reaction_message_ids: Set[int]) -> None:- @cachify+ @lru_cache(maxsize=None)def get_recipient(recipient_id: int) -> str:recipient = Recipient.objects.get(id=recipient_id)diff --git a/zerver/tests/test_decorators.py b/zerver/tests/test_decorators.pyindex 02c3b13ca41..e4abea91b98 100644--- a/zerver/tests/test_decorators.py+++ b/zerver/tests/test_decorators.py@@ -3,6 +3,7 @@ import osimport reimport uuidfrom collections import defaultdict+from functools import lru_cachefrom typing import Any, Callable, Dict, List, Optional, Sequence, Tuplefrom unittest import mock, skipUnless@@ -18,7 +19,6 @@ from zerver.decorator import (authenticated_json_view,authenticated_rest_api_view,authenticated_uploads_api_view,- cachify,internal_notify_view,is_local_addr,rate_limit,@@ -1948,7 +1948,7 @@ class RestAPITest(ZulipTestCase):class CacheTestCase(ZulipTestCase):def test_cachify_basics(self) -> None:- @cachify+ @lru_cache(maxsize=None)def add(w: Any, x: Any, y: Any, z: Any) -> Any:return w + x + y + z@@ -1962,7 +1962,7 @@ class CacheTestCase(ZulipTestCase):result_log: List[str] = []work_log: List[str] = []- @cachify+ @lru_cache(maxsize=None)def greet(first_name: str, last_name: str) -> str:msg = f"{greeting} {first_name} {last_name}"work_log.append(msg)diff --git a/zerver/tornado/event_queue.py b/zerver/tornado/event_queue.pyindex e191ff88048..d725a7d39eb 100644--- a/zerver/tornado/event_queue.py+++ b/zerver/tornado/event_queue.py@@ -11,6 +11,7 @@ import timeimport tracebackfrom collections import dequefrom dataclasses import asdict+from functools import lru_cachefrom typing import (AbstractSet,Any,@@ -38,7 +39,6 @@ from django.utils.translation import gettext as _from typing_extensions import TypedDictfrom version import API_FEATURE_LEVEL, ZULIP_MERGE_BASE, ZULIP_VERSION-from zerver.decorator import cachifyfrom zerver.lib.exceptions import JsonableErrorfrom zerver.lib.message import MessageDictfrom zerver.lib.narrow import build_narrow_filter@@ -938,7 +938,7 @@ def process_message_event(message_type: str = wide_dict["type"]sending_client: str = wide_dict["client"]- @cachify+ @lru_cache(maxsize=None)def get_client_payload(apply_markdown: bool, client_gravatar: bool) -> Dict[str, Any]:return MessageDict.finalize_payload(wide_dict,