Class: EvilQuery::ShareablesFromPerson

Inherits:
Base
  • Object
show all
Defined in:
lib/evil_query.rb

Instance Method Summary (collapse)

Methods inherited from Base

#fetch_ids!, #id_sql

Constructor Details

- (ShareablesFromPerson) initialize(querent, klass, person)

Returns a new instance of ShareablesFromPerson



114
115
116
117
118
# File 'lib/evil_query.rb', line 114

def initialize(querent, klass, person)
  @querent = querent
  @class = klass
  @person = person
end

Instance Method Details

- (Object) make_relation!



120
121
122
123
124
125
126
127
128
129
130
131
132
133
# File 'lib/evil_query.rb', line 120

def make_relation!
  return querents_posts if @person == @querent.person

  # persons_private_visibilities and persons_public_posts have no limit which is making shareable_ids gigantic.
  # perhaps they should the arrays should be merged and sorted
  # then the query at the bottom of this method can be paginated or something?

  shareable_ids = contact.present? ? fetch_ids!(persons_private_visibilities, "share_visibilities.shareable_id") : []
  shareable_ids += fetch_ids!(persons_public_posts, table_name + ".id")

  @class.where(:id => shareable_ids, :pending => false).
      select('DISTINCT '+table_name+'.*').
      order(table_name+".created_at DESC")
end