Limit tag scope nesting to six components. Rewrite multiple consecutive delimiters to one (`::`, `:::`, ... => `:`).

staging
multiple creatures 2019-05-06 00:57:25 -05:00
parent 726a99a6e4
commit db6ae92c09
1 changed files with 5 additions and 2 deletions

View File

@ -6,12 +6,15 @@ class ProcessHashtagsService < BaseService
records = []
tags.map { |str| str.mb_chars.downcase }.uniq(&:to_s).each do |name|
name = name.gsub(/::+/, ':')
component_indices = name.size.times.select {|i| name[i] == ':'}
component_indices << name.size - 1
component_indices.each do |i|
frag = name[0..i]
component_indices.take(6).each_with_index do |i, nest|
frag = (nest != 5) ? name[0..i] : name
tag = Tag.where(name: frag).first_or_create(name: frag)
p frag
status.tags << tag
next if tag.local || tag.private