mirror of https://github.com/zulip/zulip.git
bugdown: Flatten get_web_link_regex().
We use early-exit to flatten the code. I also tweaked the comments a bit based on some recent profile findings. (e.g. reading the file isn't actually a big bottleneck, it's more the regex itself)
This commit is contained in:
parent
852756aeb3
commit
eea711a805
|
@ -92,10 +92,12 @@ LINK_REGEX = None # type: Pattern
|
||||||
def get_web_link_regex() -> str:
|
def get_web_link_regex() -> str:
|
||||||
# We create this one time, but not at startup. So the
|
# We create this one time, but not at startup. So the
|
||||||
# first message rendered in any process will have some
|
# first message rendered in any process will have some
|
||||||
# extra costs.
|
# extra costs. It's roughly 75ms to run this code, so
|
||||||
|
# caching the value in LINK_REGEX is super important here.
|
||||||
global LINK_REGEX
|
global LINK_REGEX
|
||||||
if LINK_REGEX is None:
|
if LINK_REGEX is not None:
|
||||||
# NOTE: this is a very expensive step, it reads a file of tlds!
|
return LINK_REGEX
|
||||||
|
|
||||||
tlds = '|'.join(list_of_tlds())
|
tlds = '|'.join(list_of_tlds())
|
||||||
|
|
||||||
# A link starts at a word boundary, and ends at space, punctuation, or end-of-input.
|
# A link starts at a word boundary, and ends at space, punctuation, or end-of-input.
|
||||||
|
|
Loading…
Reference in New Issue