Skip to content
  • Michael Fowler's avatar
    9aa59f9d
    Avoid extraneous preloading when loading across `has_one` associations · 9aa59f9d
    Michael Fowler authored
    The Preloader relies on other objects to bind the retrieved records to their
    parents. When executed across a hash, it assumes that the results of
    `preloaded_records` is the appropriate set of records to pass in to the next
    layer.
    
    Filtering based on the reflection properties in `preloaded_records` allows us to
    avoid excessive preloading in the instance where we are loading across a
    `has_one` association distinguished by an order (e.g. "last comment" or
    similar), by dropping these records before they are returned to the
    Preloader. In this situation, we avoid potentially very long key lists in
    generated queries and the consequential AR object instantiations.
    
    This is mostly relevant if the underlying linked set has relatively many
    records, because this is effectively a multiplier on the number of records
    returned on the far side of the preload. Unfortunately, avoiding the
    over-retrieval of the `has_one` association seems to require substantial changes
    to the preloader design, and probably adaptor-specific logic -- it is a
    top-by-group problem.
    9aa59f9d
    Avoid extraneous preloading when loading across `has_one` associations
    Michael Fowler authored
    The Preloader relies on other objects to bind the retrieved records to their
    parents. When executed across a hash, it assumes that the results of
    `preloaded_records` is the appropriate set of records to pass in to the next
    layer.
    
    Filtering based on the reflection properties in `preloaded_records` allows us to
    avoid excessive preloading in the instance where we are loading across a
    `has_one` association distinguished by an order (e.g. "last comment" or
    similar), by dropping these records before they are returned to the
    Preloader. In this situation, we avoid potentially very long key lists in
    generated queries and the consequential AR object instantiations.
    
    This is mostly relevant if the underlying linked set has relatively many
    records, because this is effectively a multiplier on the number of records
    returned on the far side of the preload. Unfortunately, avoiding the
    over-retrieval of the `has_one` association seems to require substantial changes
    to the preloader design, and probably adaptor-specific logic -- it is a
    top-by-group problem.
Loading