Skip to content

Commit

Permalink
More verbose but "lazier" code
Browse files Browse the repository at this point in the history
  • Loading branch information
ceithir committed Sep 29, 2023
1 parent 5b2c54d commit d600a09
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 13 deletions.
8 changes: 6 additions & 2 deletions app/models/common_tagging.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,15 @@ def update_wrangler
end

def add_to_autocomplete
common_tag.add_to_fandom_autocomplete(filterable)
if filterable.is_a?(Fandom) && common_tag.eligible_for_fandom_autocomplete?
common_tag.add_to_fandom_autocomplete(filterable)
end
end

def remove_from_autocomplete
common_tag&.remove_from_fandom_autocomplete(filterable)
if filterable.is_a?(Fandom) && common_tag&.was_eligible_for_fandom_autocomplete?
common_tag.remove_from_fandom_autocomplete(filterable)
end
end

# A relationship should inherit its characters' fandoms
Expand Down
27 changes: 16 additions & 11 deletions app/models/tag.rb
Original file line number Diff line number Diff line change
Expand Up @@ -471,35 +471,40 @@ def autocomplete_prefixes
end

def add_to_autocomplete(score = nil)
parents.each do |parent|
add_to_fandom_autocomplete(parent, score)
if eligible_for_fandom_autocomplete?
parents.each do |parent|
add_to_fandom_autocomplete(parent, score) if parent.is_a?(Fandom)
end
end
super
end

def add_to_fandom_autocomplete(fandom, score = nil)
return unless canonical
return unless fandom.is_a?(Fandom)
return unless self.is_a?(Character) || self.is_a?(Relationship)

score ||= autocomplete_score
REDIS_AUTOCOMPLETE.zadd(self.transliterate("autocomplete_fandom_#{fandom.name.downcase}_#{type.downcase}"), score, autocomplete_value)
end

def remove_from_autocomplete
super
parents.each do |parent|
remove_from_fandom_autocomplete(parent)
if was_eligible_for_fandom_autocomplete?
parents.each do |parent|
remove_from_fandom_autocomplete(parent) if parent.is_a?(Fandom)
end
end
end

def remove_from_fandom_autocomplete(fandom)
return unless fandom.is_a?(Fandom)
return unless self.is_a?(Character) || self.is_a?(Relationship)

REDIS_AUTOCOMPLETE.zrem(self.transliterate("autocomplete_fandom_#{fandom.name.downcase}_#{type.downcase}"), autocomplete_value)
end

def eligible_for_fandom_autocomplete?
return (self.is_a?(Character) || self.is_a?(Relationship)) && canonical
end

def was_eligible_for_fandom_autocomplete?
return (self.is_a?(Character) || self.is_a?(Relationship))
end

def remove_stale_from_autocomplete
super
if self.is_a?(Character) || self.is_a?(Relationship)
Expand Down

0 comments on commit d600a09

Please sign in to comment.