Class: Gitlab::Graphql::Loaders::LazyRelationLoader::TopNLoader
- Inherits:
- 
      Object
      
        - Object
- Gitlab::Graphql::Loaders::LazyRelationLoader::TopNLoader
 
- Defined in:
- lib/gitlab/graphql/loaders/lazy_relation_loader/top_n_loader.rb
Overview
Loads the top-n records for each given parent record. For example; if you want to load only 5 confidential issues ordered by their updated_at column per project for a list of projects by issuing only a single SQL query then this class can help you. Note that the limit applies per parent record which means that if you apply limit as 5 for 10 projects, this loader will load 50 records in total.
Class Method Summary collapse
Instance Method Summary collapse
- 
  
    
      #initialize(original_relation, parents)  ⇒ TopNLoader 
    
    
  
  
  
    constructor
  
  
  
  
  
  
  
    A new instance of TopNLoader. 
- #load ⇒ Object
Constructor Details
#initialize(original_relation, parents) ⇒ TopNLoader
| 19 20 21 22 | # File 'lib/gitlab/graphql/loaders/lazy_relation_loader/top_n_loader.rb', line 19 def initialize(original_relation, parents) @original_relation = original_relation @parents = parents end | 
Class Method Details
.load(original_relation, parents) ⇒ Object
| 15 16 17 | # File 'lib/gitlab/graphql/loaders/lazy_relation_loader/top_n_loader.rb', line 15 def self.load(original_relation, parents) new(original_relation, parents).load end | 
Instance Method Details
#load ⇒ Object
| 24 25 26 27 28 29 30 31 32 | # File 'lib/gitlab/graphql/loaders/lazy_relation_loader/top_n_loader.rb', line 24 def load klass.select(klass.arel_table[Arel.star]) .from(from) .joins("JOIN LATERAL (#{lateral_relation.to_sql}) AS #{klass.arel_table.name} ON true") .includes(original_includes) .preload(original_preload) .eager_load(original_eager_load) .load end |