← Back to team overview

launchpad-reviewers team mailing list archive

Re: [Merge] lp:~cjwatson/launchpad/better-gitref-bulk-loading into lp:launchpad

 

Review: Approve code



Diff comments:

> === modified file 'lib/lp/services/database/bulk.py'
> --- lib/lp/services/database/bulk.py	2013-08-23 05:36:46 +0000
> +++ lib/lp/services/database/bulk.py	2018-08-31 13:05:56 +0000
> @@ -99,6 +102,26 @@
>          return primary_key
>  
>  
> +def _make_compound_load_clause(primary_key, values_list):
> +    """Construct a bulk-loading query clause for a compound primary key.
> +
> +    When the primary key is compound, we expect that in practice we will
> +    often want to load objects with common leading elements of the key: for
> +    example, we often want to load many `GitRef` objects from the same
> +    repository.  This helper returns a query clause optimised to be compact
> +    in this case.
> +    """
> +    if len(primary_key) > 1:
> +        return Or(*(
> +            And(
> +                primary_key[0] == leading_value,
> +                _make_compound_load_clause(
> +                    primary_key[1:], [values[1:] for values in group]))
> +            for leading_value, group in groupby(values_list, itemgetter(0))))

Does this want a sort before grouping?

> +    else:
> +        return primary_key[0].is_in([values[0] for values in values_list])
> +
> +
>  def load(object_type, primary_keys, store=None):
>      """Load a large number of objects efficiently."""
>      primary_key = _primary_key(object_type, allow_compound=True)


-- 
https://code.launchpad.net/~cjwatson/launchpad/better-gitref-bulk-loading/+merge/354112
Your team Launchpad code reviewers is subscribed to branch lp:launchpad.


References