fetch featured users from remote servers on app init unless already in the db

This commit is contained in:
danielgrippi 2011-08-02 14:36:59 -07:00
parent 6369eefdbe
commit d51e495925
4 changed files with 17 additions and 7 deletions

View file

@ -39,13 +39,7 @@ class ContactsController < ApplicationController
def featured def featured
@featured = true @featured = true
@people = [] @people = Person.featured_users
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
end end
private private

View file

@ -46,6 +46,12 @@ class Person < ActiveRecord::Base
scope :remote, where('people.owner_id IS NULL') scope :remote, where('people.owner_id IS NULL')
scope :local, where('people.owner_id IS NOT 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) def self.search_query_string(query)
query = query.downcase query = query.downcase

View 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

View file

@ -390,4 +390,7 @@ describe Person do
should == @person.as_json.merge(:tags => @person.profile.tags.map{|t| "##{t.name}"}) should == @person.as_json.merge(:tags => @person.profile.tags.map{|t| "##{t.name}"})
end end
end end
describe '.featured_users' do
end
end end