fetch featured users from remote servers on app init unless already in the db
This commit is contained in:
parent
6369eefdbe
commit
d51e495925
4 changed files with 17 additions and 7 deletions
|
|
@ -39,13 +39,7 @@ class ContactsController < ApplicationController
|
|||
|
||||
def featured
|
||||
@featured = true
|
||||
@people = []
|
||||
if diaspora_ids = AppConfig[:featured_users]
|
||||
@people = diaspora_ids.inject [] do |people, id|
|
||||
person = Webfinger.new(id).fetch
|
||||
people << person unless person.blank?
|
||||
end
|
||||
end
|
||||
@people = Person.featured_users
|
||||
end
|
||||
|
||||
private
|
||||
|
|
|
|||
|
|
@ -46,6 +46,12 @@ class Person < ActiveRecord::Base
|
|||
scope :remote, where('people.owner_id IS NULL')
|
||||
scope :local, where('people.owner_id IS NOT NULL')
|
||||
|
||||
def self.featured_users
|
||||
if AppConfig[:featured_users].present?
|
||||
Person.where(:diaspora_handle => AppConfig[:featured_users])
|
||||
end
|
||||
end
|
||||
|
||||
def self.search_query_string(query)
|
||||
query = query.downcase
|
||||
|
||||
|
|
|
|||
7
config/initializers/fetch_featured_users.rb
Normal file
7
config/initializers/fetch_featured_users.rb
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
unless AppConfig[:featured_users].count == Person.featured_users.count
|
||||
puts "Fetching featured users from remote servers..."
|
||||
AppConfig[:featured_users].each do |x|
|
||||
Webfinger.new(x).fetch
|
||||
end
|
||||
puts "Done fetching!"
|
||||
end
|
||||
|
|
@ -390,4 +390,7 @@ describe Person do
|
|||
should == @person.as_json.merge(:tags => @person.profile.tags.map{|t| "##{t.name}"})
|
||||
end
|
||||
end
|
||||
|
||||
describe '.featured_users' do
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Reference in a new issue