]> cat aescling's git repositories - mastodon.git/commitdiff
Prefix cache keys with the matcher type. #208.
authorDavid Yip <yipdw@member.fsf.org>
Thu, 16 Nov 2017 00:08:03 +0000 (18:08 -0600)
committerDavid Yip <yipdw@member.fsf.org>
Thu, 16 Nov 2017 00:12:31 +0000 (18:12 -0600)
We already know about one regex limitation, which is that they cannot
segment words in e.g. Japanese, Chinese, or Thai.  It may also end up
that regex matching is too slow compared to other methods.

However, the regex is an implementation detail.  We still want the
ability to switch between "occurs anywhere" and "match whole word", and
caching the matcher result is likely to still be important (since the
matcher itself won't change nearly as often as status ingress rate).
Therefore, we ought to be able to change the cache keys to reflect a
change of data structure.

(Old cache keys expire within minutes, so they shouldn't be too big of
an issue.  Old cache keys could also be explicitly removed by an
instance administrator.)

app/models/glitch/keyword_mute.rb

index 733dd0bc80f32a9058e876610bf4b231dfa0e0ff..001be92015819bde7ab1b7acdaf38507be4e8dee 100644 (file)
@@ -59,7 +59,7 @@ class Glitch::KeywordMute < ApplicationRecord
 
   class TextMatcher < RegexpMatcher
     def self.cache_key(account_id)
-      format('keyword_mutes:regex:%s', account_id)
+      format('keyword_mutes:regex:text:%s', account_id)
     end
 
     def =~(str)
@@ -79,7 +79,7 @@ class Glitch::KeywordMute < ApplicationRecord
 
   class TagMatcher < RegexpMatcher
     def self.cache_key(account_id)
-      format('keyword_mutes:tag:%s', account_id)
+      format('keyword_mutes:regex:tag:%s', account_id)
     end
 
     def =~(tags)