Add a batch get_matching_tags_for_images
method
This will be used in the security notification worker to retrieving the tags needed in a set of batch calls, rather than multiple calls per image
This commit is contained in:
parent
e583be3914
commit
74dd0ef8e8
4 changed files with 162 additions and 36 deletions
|
@ -6,6 +6,29 @@ from data.database import (Repository, User, Team, TeamMember, RepositoryPermiss
|
|||
Namespace, Visibility, ImageStorage, Image, RepositoryKind,
|
||||
db_for_update)
|
||||
|
||||
def reduce_as_tree(queries_to_reduce):
|
||||
""" This method will split a list of queries into halves recursively until we reach individual
|
||||
queries, at which point it will start unioning the queries, or the already unioned subqueries.
|
||||
This works around a bug in peewee SQL generation where reducing linearly generates a chain
|
||||
of queries that will exceed the recursion depth limit when it has around 80 queries.
|
||||
"""
|
||||
mid = len(queries_to_reduce)/2
|
||||
left = queries_to_reduce[:mid]
|
||||
right = queries_to_reduce[mid:]
|
||||
|
||||
to_reduce_right = right[0]
|
||||
if len(right) > 1:
|
||||
to_reduce_right = reduce_as_tree(right)
|
||||
|
||||
if len(left) > 1:
|
||||
to_reduce_left = reduce_as_tree(left)
|
||||
elif len(left) == 1:
|
||||
to_reduce_left = left[0]
|
||||
else:
|
||||
return to_reduce_right
|
||||
|
||||
return to_reduce_left.union_all(to_reduce_right)
|
||||
|
||||
|
||||
def get_existing_repository(namespace_name, repository_name, for_update=False, kind_filter=None):
|
||||
query = (Repository
|
||||
|
|
Reference in a new issue