zulip/zerver
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
..
actions notifications: Rename 'pm' to 'dm' in 'RecipientInfoResult' dataclass. 2023-08-10 17:41:49 -07:00
data_import ruff: Fix PERF102 Using only the keys/values of a dict. 2023-08-07 17:23:55 -07:00
integration_fixtures/nagios
lib per-request caches: Add per_request_cache library. 2023-08-11 11:09:34 -07:00
management send_custom_email: Add a mode which reads data from JSON. 2023-08-09 15:49:49 -07:00
migrations notification_trigger: Rename `private_message` to `direct_message`. 2023-08-10 17:41:49 -07:00
openapi notification_trigger: Rename `private_message` to `direct_message`. 2023-08-10 17:41:49 -07:00
tests per-request caches: Add per_request_cache library. 2023-08-11 11:09:34 -07:00
tornado notifications: Rename 'pm' to 'dm' in 'RecipientInfoResult' dataclass. 2023-08-10 17:41:49 -07:00
transaction_tests test_classes: Do not necessary wrap test cases in a transaction. 2023-07-06 11:44:50 -07:00
views per-request caches: Add per_request_cache library. 2023-08-11 11:09:34 -07:00
webhooks ruff: Fix PERF401 Use a list comprehension to create a transformed list. 2023-08-07 17:23:55 -07:00
worker per-request caches: Add per_request_cache library. 2023-08-11 11:09:34 -07:00
__init__.py
apps.py
context_processors.py
decorator.py logging_util: Remove dependence on get_current_request. 2023-07-11 22:23:47 -07:00
filters.py error_notify: Remove custom email error reporting handler. 2023-07-20 11:00:09 -07:00
forms.py python: Convert translated positional {} fields to {named} fields. 2023-07-18 15:19:07 -07:00
logging_handlers.py error_notify: Remove custom email error reporting handler. 2023-07-20 11:00:09 -07:00
middleware.py per-request caches: Add per_request_cache library. 2023-08-11 11:09:34 -07:00
models.py per-request caches: Add per_request_cache library. 2023-08-11 11:09:34 -07:00
signals.py