Fix public channel
This commit is contained in:
		@@ -1,8 +1,9 @@
 | 
			
		||||
class FollowSuggestion
 | 
			
		||||
  def self.get(for_account_id, limit = 10)
 | 
			
		||||
    neo = Neography::Rest.new
 | 
			
		||||
  class << self
 | 
			
		||||
    def get(for_account_id, limit = 10)
 | 
			
		||||
      neo = Neography::Rest.new
 | 
			
		||||
 | 
			
		||||
    query = <<END
 | 
			
		||||
      query = <<END
 | 
			
		||||
START a=node:account_index(Account={id})
 | 
			
		||||
MATCH (a)-[:follows]->(b)-[:follows]->(c)
 | 
			
		||||
WHERE a <> c
 | 
			
		||||
@@ -12,30 +13,30 @@ ORDER BY count(b) DESC, c.nodeRank DESC
 | 
			
		||||
LIMIT {limit}
 | 
			
		||||
END
 | 
			
		||||
 | 
			
		||||
    results = neo.execute_query(query, id: for_account_id, limit: limit)
 | 
			
		||||
      results = neo.execute_query(query, id: for_account_id, limit: limit)
 | 
			
		||||
 | 
			
		||||
    if results.empty? || results['data'].empty?
 | 
			
		||||
      results = fallback(for_account_id, limit)
 | 
			
		||||
    elsif results['data'].size < limit
 | 
			
		||||
      results['data'] = (results['data'] + fallback(for_account_id, limit - results['data'].size)['data']).uniq
 | 
			
		||||
      if results.empty? || results['data'].empty?
 | 
			
		||||
        results = fallback(for_account_id, limit)
 | 
			
		||||
      elsif results['data'].size < limit
 | 
			
		||||
        results['data'] = (results['data'] + fallback(for_account_id, limit - results['data'].size)['data']).uniq
 | 
			
		||||
      end
 | 
			
		||||
 | 
			
		||||
      account_ids  = results['data'].map(&:first)
 | 
			
		||||
      blocked_ids  = Block.where(account_id: for_account_id).pluck(:target_account_id)
 | 
			
		||||
      accounts_map = Account.where(id: account_ids - blocked_ids).with_counters.map { |a| [a.id, a] }.to_h
 | 
			
		||||
 | 
			
		||||
      account_ids.map { |id| accounts_map[id] }.compact
 | 
			
		||||
    rescue Neography::NeographyError, Excon::Error::Socket => e
 | 
			
		||||
      Rails.logger.error e
 | 
			
		||||
      return []
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    account_ids  = results['data'].map(&:first)
 | 
			
		||||
    blocked_ids  = Block.where(account_id: for_account_id).pluck(:target_account_id)
 | 
			
		||||
    accounts_map = Account.where(id: account_ids - blocked_ids).with_counters.map { |a| [a.id, a] }.to_h
 | 
			
		||||
    private
 | 
			
		||||
 | 
			
		||||
    account_ids.map { |id| accounts_map[id] }.compact
 | 
			
		||||
  rescue Neography::NeographyError, Excon::Error::Socket => e
 | 
			
		||||
    Rails.logger.error e
 | 
			
		||||
    return []
 | 
			
		||||
  end
 | 
			
		||||
    def fallback(for_account_id, limit)
 | 
			
		||||
      neo = Neography::Rest.new
 | 
			
		||||
 | 
			
		||||
  private
 | 
			
		||||
 | 
			
		||||
  def self.fallback(for_account_id, limit)
 | 
			
		||||
    neo = Neography::Rest.new
 | 
			
		||||
 | 
			
		||||
    query = <<END
 | 
			
		||||
      query = <<END
 | 
			
		||||
START a=node:account_index(Account={id})
 | 
			
		||||
MATCH (b)
 | 
			
		||||
WHERE a <> b
 | 
			
		||||
@@ -45,6 +46,7 @@ ORDER BY b.nodeRank DESC
 | 
			
		||||
LIMIT {limit}
 | 
			
		||||
END
 | 
			
		||||
 | 
			
		||||
    neo.execute_query(query, id: for_account_id, limit: limit)
 | 
			
		||||
      neo.execute_query(query, id: for_account_id, limit: limit)
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
 
 | 
			
		||||
@@ -34,26 +34,28 @@ class MediaAttachment < ApplicationRecord
 | 
			
		||||
    image? ? 'image' : 'video'
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  private
 | 
			
		||||
  class << self
 | 
			
		||||
    private
 | 
			
		||||
 | 
			
		||||
  def self.file_styles(f)
 | 
			
		||||
    if f.instance.image?
 | 
			
		||||
      {
 | 
			
		||||
        original: '100%',
 | 
			
		||||
        small: '510x680>'
 | 
			
		||||
      }
 | 
			
		||||
    else
 | 
			
		||||
      {
 | 
			
		||||
        small: {
 | 
			
		||||
          convert_options: {
 | 
			
		||||
            output: {
 | 
			
		||||
              vf: 'scale=\'min(510\, iw):min(680\, ih)\':force_original_aspect_ratio=decrease'
 | 
			
		||||
            }
 | 
			
		||||
          },
 | 
			
		||||
          format: 'png',
 | 
			
		||||
          time: 1
 | 
			
		||||
    def file_styles(f)
 | 
			
		||||
      if f.instance.image?
 | 
			
		||||
        {
 | 
			
		||||
          original: '100%',
 | 
			
		||||
          small: '510x680>'
 | 
			
		||||
        }
 | 
			
		||||
      }
 | 
			
		||||
      else
 | 
			
		||||
        {
 | 
			
		||||
          small: {
 | 
			
		||||
            convert_options: {
 | 
			
		||||
              output: {
 | 
			
		||||
                vf: 'scale=\'min(510\, iw):min(680\, ih)\':force_original_aspect_ratio=decrease'
 | 
			
		||||
              }
 | 
			
		||||
            },
 | 
			
		||||
            format: 'png',
 | 
			
		||||
            time: 1
 | 
			
		||||
          }
 | 
			
		||||
        }
 | 
			
		||||
      end
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user