realm emoji: Use a single cache for all lookups.

The active realm emoji are just a subset of all your
realm emoji, so just use a single cache entry per
realm.

Cache misses should be very infrequent per realm.

If a realm has lots of deactivated realm emoji, then
there's a minor expense to deserialize them, but that
is gonna be dwarfed by all the other more expensive
operations in message-send.

I also renamed the two related functions.  I erred on
the side of using somewhat verbose names, as we don't
want folks to confuse the two use cases. Fortunately
there are somewhat natural affordances to use one or
the other, and mypy helps too.

Finally, I use realm_id instead of realm in places
where we don't need the full Realm object.
This commit is contained in:
Steve Howell
2023-07-14 10:37:29 +00:00
committed by Tim Abbott
parent e988cf9b0a
commit b742f1241f
8 changed files with 58 additions and 48 deletions

View File

@@ -67,6 +67,7 @@ from zerver.models import (
UserStatus,
UserTopic,
custom_profile_fields_for_realm,
get_all_custom_emoji_for_realm,
get_default_stream_groups,
get_realm_domains,
get_realm_playgrounds,
@@ -384,7 +385,7 @@ def fetch_initial_state_data(
state["realm_domains"] = get_realm_domains(realm)
if want("realm_emoji"):
state["realm_emoji"] = realm.get_emoji()
state["realm_emoji"] = get_all_custom_emoji_for_realm(realm.id)
if want("realm_linkifiers"):
if linkifier_url_template: