l.s.d.bulk : module documentation

Part of lp.services.database

Optimized bulk operations against the database.
Function collate Collate the given objects according to a key function.
Function get_type Return the type of the given object.
Function gen_reload_queries Prepare queries to reload the given objects.
Function reload Reload a large number of objects efficiently.
Function load Load a large number of objects efficiently.
Function load_referencing Load objects of object_type that reference owning_objects.
Function load_related Load objects of object_type referred to by owning_objects.
Function dbify_value Convert a value into a form that Storm can compile directly.
Function dbify_column Convert a column into a form that Storm can compile directly.
Function create Create a large number of objects efficiently.
Function _primary_key Get a primary key our helpers can use.
Function _make_compound_load_clause Construct a bulk-loading query clause for a compound primary key.
def collate(things, key):
Collate the given objects according to a key function.

Generates (common-key-value, list-of-things) tuples, like groupby, except that the given objects do not need to be sorted.

def get_type(thing):
Return the type of the given object.

If the given object is wrapped by a security proxy, the type returned is that of the wrapped object.

def gen_reload_queries(objects):
Prepare queries to reload the given objects.
def reload(objects):
Reload a large number of objects efficiently.
def _primary_key(object_type, allow_compound=False):
Get a primary key our helpers can use.

:raises AssertionError if the key is missing or unusable.

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.

Parametersprimary_keyThe primary key columns.
values_listA sequence of values of the primary key whose corresponding rows should be loaded. This must be sorted by the caller (because this function calls itself recursively, and it's usually more efficient to sort the whole sequence in one go).
def load(object_type, primary_keys, store=None):
Load a large number of objects efficiently.
def load_referencing(object_type, owning_objects, reference_keys, extra_conditions=):
Load objects of object_type that reference owning_objects.

Note that complex types like Person are best loaded through dedicated helpers that can eager load other related things (e.g. validity for Person).

Parametersobject_typeThe object type to load - e.g. BranchSubscription.
owning_objectsThe objects which are referenced. E.g. [Branch()] At this point, all the objects should be of the same type, but that constraint could be lifted in future.
reference_keysA list of attributes that should be used to select object_type keys. e.g. ['branchID']
extra_conditionsA list of Storm clauses that will be used in the final query.
ReturnsA list of object_type where any of reference_keys refered to the primary key of any of owning_objects.
def load_related(object_type, owning_objects, foreign_keys):
Load objects of object_type referred to by owning_objects.

Note that complex types like Person are best loaded through dedicated helpers that can eager load other related things (e.g. validity for Person).

Parametersobject_typeThe object type to load - e.g. Person.
owning_objectsThe objects holding the references. E.g. Bug.
foreign_keysA list of attributes that should be inspected for keys. e.g. ['ownerID']
def dbify_value(col, val):
Convert a value into a form that Storm can compile directly.
def dbify_column(col):
Convert a column into a form that Storm can compile directly.
def create(columns, values, get_objects=False, get_primary_keys=False):
Create a large number of objects efficiently.
ParameterscolumnsThe Storm columns to insert values into. Must be from a single class.
valuesA list of lists of values for the columns.
get_objectsReturn the created objects.
get_primary_keysReturn the created primary keys.
ReturnsA list of the created objects if get_created, otherwise None.
API Documentation for Launchpad, generated by pydoctor at 2022-06-16 00:00:12.