zulip/zerver/views
Steve Howell 51db22c86c per-request caches: Add per_request_cache library.
We have historically cached two types of values
on a per-request basis inside of memory:

    * linkifiers
    * display recipients

Both of these caches were hand-written, and they
both actually cache values that are also in memcached,
so the per-request cache essentially only saves us
from a few memcached hits.

I think the linkifier per-request cache is a necessary
evil. It's an important part of message rendering, and
it's not super easy to structure the code to just get
a single value up front and pass it down the stack.

I'm not so sure we even need the display recipient
per-request cache any more, as we are generally pretty
smart now about hydrating recipient data in terms of
how the code is organized. But I haven't done thorough
research on that hypotheseis.

Fortunately, it's not rocket science to just write
a glorified memoize decorator and tie it into key
places in the code:

    * middleware
    * tests (e.g. asserting db counts)
    * queue processors

That's what I did in this commit.

This commit definitely reduces the amount of code
to maintain. I think it also gets us closer to
possibly phasing out this whole technique, but that
effort is beyond the scope of this PR. We could
add some instrumentation to the decorator to see
how often we get a non-trivial number of saved
round trips to memcached.

Note that when we flush linkifiers, we just use
a big hammer and flush the entire per-request
cache for linkifiers, since there is only ever
one realm in the cache.
2023-08-11 11:09:34 -07:00
..
development per-request caches: Add per_request_cache library. 2023-08-11 11:09:34 -07:00
__init__.py
alert_words.py actions: Split out zerver.actions.alert_words. 2022-04-14 17:14:31 -07:00
attachments.py actions: Split out zerver.actions.uploads. 2022-04-14 17:14:32 -07:00
auth.py python: Annotate type aliases with TypeAlias. 2023-08-07 10:02:49 -07:00
compatibility.py django: Use HttpRequest.headers. 2022-05-13 20:42:20 -07:00
custom_profile_fields.py ruff: Fix PLR1714 Consider merging multiple comparisons. 2023-07-23 15:21:33 -07:00
digest.py mypy: Fix most AnonymousUser type errors. 2021-07-24 14:55:46 -07:00
documentation.py api_url_context: Replace `uri` with `url`. 2023-04-26 16:37:16 -07:00
drafts.py backend: Add request as parameter to json_success. 2022-02-04 15:16:56 -08:00
email_mirror.py backend: Add request as parameter to json_success. 2022-02-04 15:16:56 -08:00
events_register.py python: Annotate type aliases with TypeAlias. 2023-08-07 10:02:49 -07:00
home.py narrow: Split out narrow_helpers. 2023-06-30 11:26:23 -07:00
hotspots.py python: Convert translated positional {} fields to {named} fields. 2023-07-18 15:19:07 -07:00
invite.py python: Convert translated positional {} fields to {named} fields. 2023-07-18 15:19:07 -07:00
message_edit.py black: Reformat with Black 23. 2023-02-02 10:40:13 -08:00
message_fetch.py python: Convert translated positional {} fields to {named} fields. 2023-07-18 15:19:07 -07:00
message_flags.py python: Convert translated positional {} fields to {named} fields. 2023-07-18 15:19:07 -07:00
message_send.py ruff: Collapse short multi-line import statements. 2023-08-02 17:41:41 -07:00
muted_users.py muted users: Add support to muting bots. 2023-06-13 16:44:12 -07:00
presence.py python: Convert translated positional {} fields to {named} fields. 2023-07-18 15:19:07 -07:00
push_notifications.py backend: Add request as parameter to json_success. 2022-02-04 15:16:56 -08:00
reactions.py reactions: Add error code for duplicate addition/removal. 2023-07-19 16:18:31 -07:00
read_receipts.py read_receipts: Exclude muted users from read receipts. 2022-09-16 16:19:54 -07:00
realm.py realm-settings: Make default_code_block_language empty string as default. 2023-07-21 18:54:02 +02:00
realm_domains.py python: Convert translated positional {} fields to {named} fields. 2023-07-18 15:19:07 -07:00
realm_emoji.py ruff: Fix RUF015 Prefer `next(...)` over single element slice. 2023-07-23 15:20:53 -07:00
realm_export.py realm_export: Return export id from POST which create it. 2023-05-16 14:05:01 -07:00
realm_icon.py ruff: Fix RUF015 Prefer `next(...)` over single element slice. 2023-07-23 15:20:53 -07:00
realm_linkifiers.py linkifier: Support URL templates for linkifiers. 2023-04-19 12:20:49 -07:00
realm_logo.py ruff: Fix RUF015 Prefer `next(...)` over single element slice. 2023-07-23 15:20:53 -07:00
realm_playgrounds.py realm_playgrounds: Refactor error handling for validation on creation. 2023-07-24 17:40:59 -07:00
registration.py saml: Make SP-initiated SLO work after signup. 2023-05-23 13:01:15 -07:00
report.py ruff: Collapse short multi-line import statements. 2023-08-02 17:41:41 -07:00
scheduled_messages.py scheduled-messages: Update scheduled_message_id parameter for DELETE. 2023-05-31 08:15:03 -07:00
sentry.py ruff: Collapse short multi-line import statements. 2023-08-02 17:41:41 -07:00
storage.py backend: Add request as parameter to json_success. 2022-02-04 15:16:56 -08:00
streams.py stream_settings: Add 'Default stream' option in create stream UI. 2023-08-09 15:20:09 -07:00
submessage.py actions: Split out zerver.actions.submessage. 2022-04-14 17:14:30 -07:00
thumbnail.py docs: Remove some outdated references to thumbnailing.md doc. 2022-07-12 17:44:24 -07:00
tutorial.py backend: Add request as parameter to json_success. 2022-02-04 15:16:56 -08:00
typing.py message-type: Add support for "direct" as value for type parameter. 2023-04-18 12:29:33 -07:00
unsubscribe.py black: Reformat with Black 23. 2023-02-02 10:40:13 -08:00
upload.py ruff: Fix RUF015 Prefer `next(...)` over single element slice. 2023-07-23 15:20:53 -07:00
user_groups.py user_groups: Update code for changing group level settings. 2023-08-06 13:42:52 -07:00
user_settings.py ruff: Fix RUF015 Prefer `next(...)` over single element slice. 2023-07-23 15:20:53 -07:00
user_topics.py user_topics: Add a new endpoint to update visibility_policy. 2023-04-03 22:31:49 -07:00
users.py ruff: Fix RUF015 Prefer `next(...)` over single element slice. 2023-07-23 15:20:53 -07:00
video_calls.py actions: Split out zerver.actions.video_calls. 2022-04-14 17:14:30 -07:00
zephyr.py ruff: Fix PLW0602 Using global but no assignment is done. 2023-01-04 16:25:07 -08:00