Merge commit '82e477b184b5666fff7fb55933dce22ca2925db8' into glitch-soc/merge-upstream
Conflicts: - `db/migrate/20180831171112_create_bookmarks.rb`: Upstream ran a lint fix on this file, but this file is different in glitch-soc because the feature was added much earlier. Ran the lint fix on our own version of the file.
This commit is contained in:
@@ -25,7 +25,7 @@ class AccountAlias < ApplicationRecord
|
||||
|
||||
def acct=(val)
|
||||
val = val.to_s.strip
|
||||
super(val.start_with?('@') ? val[1..-1] : val)
|
||||
super(val.start_with?('@') ? val[1..] : val)
|
||||
end
|
||||
|
||||
def pretty_acct
|
||||
|
@@ -69,7 +69,7 @@ class DomainBlock < ApplicationRecord
|
||||
|
||||
uri = Addressable::URI.new.tap { |u| u.host = domain.strip.delete('/') }
|
||||
segments = uri.normalized_host.split('.')
|
||||
variants = segments.map.with_index { |_, i| segments[i..-1].join('.') }
|
||||
variants = segments.map.with_index { |_, i| segments[i..].join('.') }
|
||||
|
||||
where(domain: variants).order(Arel.sql('char_length(domain) desc')).first
|
||||
rescue Addressable::URI::InvalidURIError, IDN::Idna::IdnaError
|
||||
|
@@ -64,7 +64,7 @@ class EmailDomainBlock < ApplicationRecord
|
||||
|
||||
segments = uri.normalized_host.split('.')
|
||||
|
||||
segments.map.with_index { |_, i| segments[i..-1].join('.') }
|
||||
segments.map.with_index { |_, i| segments[i..].join('.') }
|
||||
end
|
||||
end
|
||||
|
||||
|
@@ -54,6 +54,6 @@ class PreviewCardProvider < ApplicationRecord
|
||||
|
||||
def self.matching_domain(domain)
|
||||
segments = domain.split('.')
|
||||
where(domain: segments.map.with_index { |_, i| segments[i..-1].join('.') }).order(Arel.sql('char_length(domain) desc')).first
|
||||
where(domain: segments.map.with_index { |_, i| segments[i..].join('.') }).order(Arel.sql('char_length(domain) desc')).first
|
||||
end
|
||||
end
|
||||
|
@@ -68,12 +68,10 @@ class Trends::Query
|
||||
alias to_a to_ary
|
||||
|
||||
def to_arel
|
||||
tmp_ids = ids
|
||||
|
||||
if tmp_ids.empty?
|
||||
if ids_for_key.empty?
|
||||
klass.none
|
||||
else
|
||||
scope = klass.joins("join unnest(array[#{tmp_ids.join(',')}]) with ordinality as x (id, ordering) on #{klass.table_name}.id = x.id").reorder('x.ordering')
|
||||
scope = klass.joins(sanitized_join_sql).reorder('x.ordering')
|
||||
scope = scope.offset(@offset) if @offset.present?
|
||||
scope = scope.limit(@limit) if @limit.present?
|
||||
scope
|
||||
@@ -95,8 +93,22 @@ class Trends::Query
|
||||
self
|
||||
end
|
||||
|
||||
def ids
|
||||
redis.zrevrange(key, 0, -1).map(&:to_i)
|
||||
def ids_for_key
|
||||
@ids_for_key ||= redis.zrevrange(key, 0, -1).map(&:to_i)
|
||||
end
|
||||
|
||||
def sanitized_join_sql
|
||||
ActiveRecord::Base.sanitize_sql_array(join_sql_array)
|
||||
end
|
||||
|
||||
def join_sql_array
|
||||
[join_sql_query, ids_for_key]
|
||||
end
|
||||
|
||||
def join_sql_query
|
||||
<<~SQL.squish
|
||||
JOIN unnest(array[?]) WITH ordinality AS x (id, ordering) ON #{klass.table_name}.id = x.id
|
||||
SQL
|
||||
end
|
||||
|
||||
def perform_queries
|
||||
|
Reference in New Issue
Block a user