+ protected
+
+ def load_searchable_objects opts
+ all_objects = []
+ @items_available = 0
+
+ # Trick apply_where_limit_order_params into applying suitable
+ # per-table values. *_all are the real ones we'll apply to the
+ # aggregate set.
+ limit_all = @limit
+ offset_all = @offset
+ @orders = []
+
+ [Group,
+ Job, PipelineInstance, PipelineTemplate,
+ Collection,
+ Human, Specimen, Trait].each do |klass|
+ @objects = klass.readable_by(*@read_users)
+ conds = []
+ cond_params = []
+ if opts[:owner_uuid]
+ conds << "#{klass.table_name}.owner_uuid = ?"
+ cond_params << opts[:owner_uuid]
+ end
+ if opts[:include_linked]
+ conds << "#{klass.table_name}.uuid IN (SELECT head_uuid FROM links WHERE link_class=#{klass.sanitize 'name'} AND links.tail_uuid=#{klass.sanitize @object.uuid})"
+ end
+ if conds.any?
+ cond_sql = '(' + conds.join(') OR (') + ')'
+ @objects = @objects.where(cond_sql, *cond_params)
+ end
+ @objects = @objects.order("#{klass.table_name}.uuid")
+ @limit = limit_all - all_objects.count
+ apply_where_limit_order_params
+ klass_items_available = @objects.
+ except(:limit).except(:offset).
+ count(:id, distinct: true)
+ @items_available += klass_items_available
+ @offset = [@offset - klass_items_available, 0].max
+
+ all_objects += @objects.to_a
+ end
+
+ @objects = all_objects
+ @limit = limit_all
+ @offset = offset_all
+ end
+