From 993965b654d050995e906654dbae96a3588dfb0e Mon Sep 17 00:00:00 2001 From: evazion Date: Thu, 16 Dec 2021 16:30:31 -0600 Subject: [PATCH] posts: reduce string allocations during thumbnail generation. Further micro-optimize thumbnails to reduce string allocations. `Post#levelblocked?` gets called once per thumbnail. Before it split the tag string, which meant one string allocation for each tag on each post. This added up to thousands of string allocations per pageload. --- app/models/post.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/models/post.rb b/app/models/post.rb index 3584920e3..1fffe9524 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -8,7 +8,7 @@ class Post < ApplicationRecord NOTE_COPY_TAGS = %w[translated partially_translated check_translation translation_request reverse_translation annotated partially_annotated check_annotation annotation_request] - RESTRICTED_TAGS = Danbooru.config.restricted_tags + RESTRICTED_TAGS_REGEX = /(?:^| )(?:#{Danbooru.config.restricted_tags.join("|")})(?:$| )/o self.ignored_columns = [:pool_string, :fav_string] @@ -1289,7 +1289,8 @@ class Post < ApplicationRecord end def levelblocked?(user = CurrentUser.user) - !user.is_gold? && RESTRICTED_TAGS.any? { |tag| tag.in?(tag_array) } + #!user.is_gold? && RESTRICTED_TAGS.any? { |tag| has_tag?(tag) } + !user.is_gold? && tag_string.match?(RESTRICTED_TAGS_REGEX) end def banblocked?(user = CurrentUser.user)