Change repo filtering for users to use a user ID reference, rather than the username
While this means we need an additional query for initial lookup, it makes the *filtering* query (which is the heavy part) require far fewer joins, thus making it more efficient. Also adds a new unit test to verify that our filter filters to the correct set of repositories.
This commit is contained in:
parent
f2b9aa4527
commit
7604e9842b
7 changed files with 158 additions and 34 deletions
|
@ -12,12 +12,18 @@ from data.model import (DataModelException, db_transaction, _basequery, storage,
|
|||
InvalidImageException)
|
||||
from data.database import (Image, Repository, ImageStoragePlacement, Namespace, ImageStorage,
|
||||
ImageStorageLocation, RepositoryPermission, DerivedStorageForImage,
|
||||
ImageStorageTransformation)
|
||||
ImageStorageTransformation, User)
|
||||
|
||||
from util.canonicaljson import canonicalize
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
def _namespace_id_for_username(username):
|
||||
try:
|
||||
return User.get(username=username).id
|
||||
except User.DoesNotExist:
|
||||
return None
|
||||
|
||||
|
||||
def get_image_with_storage(docker_image_id, storage_uuid):
|
||||
""" Returns the image with the given docker image ID and storage uuid or None if none.
|
||||
|
@ -273,7 +279,8 @@ def find_create_or_link_image(docker_image_id, repo_obj, username, translations,
|
|||
.where(ImageStorage.uploading == False,
|
||||
Image.docker_image_id == docker_image_id))
|
||||
|
||||
existing_image_query = _basequery.filter_to_repos_for_user(existing_image_query, username)
|
||||
existing_image_query = _basequery.filter_to_repos_for_user(existing_image_query,
|
||||
_namespace_id_for_username(username))
|
||||
|
||||
# If there is an existing image, we try to translate its ancestry and copy its storage.
|
||||
new_image = None
|
||||
|
|
Reference in a new issue