From b13e7dda1f33be43d1667b754b67df71f3187a5c Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Wed, 9 Nov 2016 17:48:44 +0100 Subject: API pagination for all collections using Link header --- app/models/account.rb | 50 ++++++++++++++++++++++++++------------------------ 1 file changed, 26 insertions(+), 24 deletions(-) (limited to 'app/models/account.rb') diff --git a/app/models/account.rb b/app/models/account.rb index 92286369e..4fb0baebe 100644 --- a/app/models/account.rb +++ b/app/models/account.rb @@ -133,36 +133,38 @@ class Account < ApplicationRecord [] end - def self.find_local!(username) - find_remote!(username, nil) - end + class << self + def find_local!(username) + find_remote!(username, nil) + end - def self.find_remote!(username, domain) - where(arel_table[:username].matches(username)).where(domain.nil? ? { domain: nil } : arel_table[:domain].matches(domain)).take! - end + def find_remote!(username, domain) + where(arel_table[:username].matches(username)).where(domain.nil? ? { domain: nil } : arel_table[:domain].matches(domain)).take! + end - def self.find_local(username) - find_local!(username) - rescue ActiveRecord::RecordNotFound - nil - end + def find_local(username) + find_local!(username) + rescue ActiveRecord::RecordNotFound + nil + end - def self.find_remote(username, domain) - find_remote!(username, domain) - rescue ActiveRecord::RecordNotFound - nil - end + def find_remote(username, domain) + find_remote!(username, domain) + rescue ActiveRecord::RecordNotFound + nil + end - def self.following_map(target_account_ids, account_id) - Follow.where(target_account_id: target_account_ids).where(account_id: account_id).map { |f| [f.target_account_id, true] }.to_h - end + def following_map(target_account_ids, account_id) + Follow.where(target_account_id: target_account_ids).where(account_id: account_id).map { |f| [f.target_account_id, true] }.to_h + end - def self.followed_by_map(target_account_ids, account_id) - Follow.where(account_id: target_account_ids).where(target_account_id: account_id).map { |f| [f.account_id, true] }.to_h - end + def followed_by_map(target_account_ids, account_id) + Follow.where(account_id: target_account_ids).where(target_account_id: account_id).map { |f| [f.account_id, true] }.to_h + end - def self.blocking_map(target_account_ids, account_id) - Block.where(target_account_id: target_account_ids).where(account_id: account_id).map { |b| [b.target_account_id, true] }.to_h + def blocking_map(target_account_ids, account_id) + Block.where(target_account_id: target_account_ids).where(account_id: account_id).map { |b| [b.target_account_id, true] }.to_h + end end before_create do -- cgit