about summary refs log tree commit diff
path: root/app/models/tag_filter.rb
diff options
context:
space:
mode:
authorEugen Rochko <eugen@zeonfederated.com>2022-02-25 00:34:14 +0100
committerGitHub <noreply@github.com>2022-02-25 00:34:14 +0100
commit27965ce5edff20db2de1dd233c88f8393bb0da0b (patch)
tree6714a950c1b9facc8c7bd1907e81e777257e5538 /app/models/tag_filter.rb
parenta29a982eaa0536a741b43ffb3397c74e3abe7196 (diff)
Add trending statuses (#17431)
* Add trending statuses

* Fix dangling items with stale scores in localized sets

* Various fixes and improvements

- Change approve_all/reject_all to approve_accounts/reject_accounts
- Change Trends::Query methods to not mutate the original query
- Change Trends::Query#skip to offset
- Change follow recommendations to be refreshed in a transaction

* Add tests for trending statuses filtering behaviour

* Fix not applying filtering scope in controller
Diffstat (limited to 'app/models/tag_filter.rb')
-rw-r--r--app/models/tag_filter.rb66
1 files changed, 0 insertions, 66 deletions
diff --git a/app/models/tag_filter.rb b/app/models/tag_filter.rb
deleted file mode 100644
index ecdb52503..000000000
--- a/app/models/tag_filter.rb
+++ /dev/null
@@ -1,66 +0,0 @@
-# frozen_string_literal: true
-
-class TagFilter
-  KEYS = %i(
-    trending
-    status
-  ).freeze
-
-  attr_reader :params
-
-  def initialize(params)
-    @params = params
-  end
-
-  def results
-    scope = begin
-      if params[:status] == 'pending_review'
-        Tag.unscoped
-      else
-        trending_scope
-      end
-    end
-
-    params.each do |key, value|
-      next if key.to_s == 'page'
-
-      scope.merge!(scope_for(key, value.to_s.strip)) if value.present?
-    end
-
-    scope
-  end
-
-  private
-
-  def scope_for(key, value)
-    case key.to_s
-    when 'status'
-      status_scope(value)
-    else
-      raise "Unknown filter: #{key}"
-    end
-  end
-
-  def trending_scope
-    ids = Trends.tags.currently_trending_ids(false, -1)
-
-    if ids.empty?
-      Tag.none
-    else
-      Tag.joins("join unnest(array[#{ids.map(&:to_i).join(',')}]::integer[]) with ordinality as x (id, ordering) on tags.id = x.id").order('x.ordering')
-    end
-  end
-
-  def status_scope(value)
-    case value.to_s
-    when 'approved'
-      Tag.trendable
-    when 'rejected'
-      Tag.not_trendable
-    when 'pending_review'
-      Tag.pending_review
-    else
-      raise "Unknown status: #{value}"
-    end
-  end
-end