mirror of
https://github.com/jointakahe/takahe.git
synced 2024-11-22 07:10:59 +00:00
Modify emoji loader for cache-optimized return value (#371)
Also fixes an apparent bug in `imageify_emojis.replacer` where `include_local` was not being used correctly (previous code path never returned anything.
This commit is contained in:
parent
db186fcd73
commit
d8cee4097f
2 changed files with 16 additions and 14 deletions
|
@ -146,15 +146,18 @@ class Emoji(StatorModel):
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
@cached(cache=TTLCache(maxsize=1000, ttl=60))
|
@cached(cache=TTLCache(maxsize=1000, ttl=60))
|
||||||
def get_by_domain(cls, shortcode, domain: Domain | None) -> "Emoji":
|
def get_by_domain(cls, shortcode, domain: Domain | None) -> "Emoji | None":
|
||||||
"""
|
"""
|
||||||
Given an emoji shortcode and optional domain, looks up the single
|
Given an emoji shortcode and optional domain, looks up the single
|
||||||
emoji and returns it. Raises Emoji.DoesNotExist if there isn't one.
|
emoji and returns it. Raises Emoji.DoesNotExist if there isn't one.
|
||||||
"""
|
"""
|
||||||
if domain is None or domain.local:
|
try:
|
||||||
return cls.objects.get(local=True, shortcode=shortcode)
|
if domain is None or domain.local:
|
||||||
else:
|
return cls.objects.get(local=True, shortcode=shortcode)
|
||||||
return cls.objects.get(domain=domain, shortcode=shortcode)
|
else:
|
||||||
|
return cls.objects.get(domain=domain, shortcode=shortcode)
|
||||||
|
except Emoji.DoesNotExist:
|
||||||
|
return None
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def fullcode(self):
|
def fullcode(self):
|
||||||
|
|
17
core/html.py
17
core/html.py
|
@ -214,16 +214,15 @@ class ContentRenderer:
|
||||||
shortcode = match.group(1).lower()
|
shortcode = match.group(1).lower()
|
||||||
if shortcode in cached_emojis:
|
if shortcode in cached_emojis:
|
||||||
return cached_emojis[shortcode].as_html()
|
return cached_emojis[shortcode].as_html()
|
||||||
try:
|
|
||||||
emoji = Emoji.get_by_domain(shortcode, identity.domain)
|
emoji = Emoji.get_by_domain(shortcode, identity.domain)
|
||||||
if emoji.is_usable:
|
if emoji and emoji.is_usable:
|
||||||
|
return emoji.as_html()
|
||||||
|
elif not emoji and include_local:
|
||||||
|
emoji = Emoji.get_by_domain(shortcode, None)
|
||||||
|
if emoji:
|
||||||
return emoji.as_html()
|
return emoji.as_html()
|
||||||
except Emoji.DoesNotExist:
|
|
||||||
if include_local:
|
|
||||||
try:
|
|
||||||
return Emoji.get_by_domain(shortcode, identity.domain).as_html()
|
|
||||||
except Emoji.DoesNotExist:
|
|
||||||
pass
|
|
||||||
return match.group()
|
return match.group()
|
||||||
|
|
||||||
return Emoji.emoji_regex.sub(replacer, html)
|
return Emoji.emoji_regex.sub(replacer, html)
|
||||||
|
|
Loading…
Reference in a new issue