Class: Pipeline::GrouperByParentAndSubmission

Inherits:
GrouperForPipeline show all
Defined in:
app/models/pipeline/grouper_by_parent_and_submission.rb

Overview

Some pipelines group requests together in the inbox, such that all requests in a plate and submission MUST be selected together. This takes the selected checkboxes and splits the information back out to the individual requests.

Instance Method Summary collapse

Methods inherited from GrouperForPipeline

#base_scope, #initialize

Constructor Details

This class inherits a constructor from Pipeline::GrouperForPipeline

Instance Method Details

#all(selected_groups) ⇒ Object


7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'app/models/pipeline/grouper_by_parent_and_submission.rb', line 7

def all(selected_groups)
  queries = selected_groups.map { |group| extract_conditions(group) }

  # We build out own OR query by hand, as the built in Rails support will raise
  # a SystemStackError when face with a large number of `selected_groups`.
  # This is beacuse it processes the various conditions in a recursive manner.
  # For example, the following is throwing a `SystemStackError`.
  # @example (2...800).reduce(Request.where(id:1)) {|a,b| a.or(Request.where(id: b)) }.to_sql
  # Be a little cautious before making changes to use native arel, as internal
  # changes in arel, and the stack limits of the Ruby VM, may cause the problem
  # to trigger at different levels. We probably only want to switch to the
  # native function when it no longer builds its queries recursively. (Or when
  # ruby handles recursive method calls differently.)
  combined_queries = queries.join(' OR ').presence || 'FALSE'
  base_scope.where(combined_queries)
end