From 5c4b7c128471b2ea088592a2fd986f403ce65419 Mon Sep 17 00:00:00 2001 From: Shish Date: Fri, 16 Feb 2024 16:41:00 +0000 Subject: [PATCH] [post_tags] avoid DB call if not needed --- ext/post_tags/main.php | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/ext/post_tags/main.php b/ext/post_tags/main.php index 86486663..452556ca 100644 --- a/ext/post_tags/main.php +++ b/ext/post_tags/main.php @@ -186,10 +186,14 @@ class PostTags extends Extension public function onParseLinkTemplate(ParseLinkTemplateEvent $event): void { - $tags = $event->image->get_tag_list(); - $tags = str_replace("/", "", $tags); - $tags = ltrim($tags, "."); - $event->replace('$tags', $tags); + // get_tag_list can trigger a database query, + // so we only want to do it if we need to + if (str_contains($event->link, '$tags')) { + $tags = $event->image->get_tag_list(); + $tags = str_replace("/", "", $tags); + $tags = ltrim($tags, "."); + $event->replace('$tags', $tags); + } } private function mass_tag_edit(string $search, string $replace, bool $commit): void