Move the creation of images to when the JSON is uploaded.

This commit is contained in:
Jake Moshenko 2015-02-13 16:28:45 -05:00
parent 3cae6609a7
commit 59b794dd61
3 changed files with 12 additions and 33 deletions

View file

@ -222,32 +222,6 @@ def create_repository(namespace, repository):
repo = model.create_repository(namespace, repository,
get_authenticated_user())
logger.debug('Determining already added images')
added_images = OrderedDict([(desc['id'], desc) for desc in image_descriptions])
new_repo_images = dict(added_images)
# Optimization: Lookup any existing images in the repository with matching docker IDs and
# remove them from the added dict, so we don't need to look them up one-by-one.
def chunks(l, n):
for i in xrange(0, len(l), n):
yield l[i:i+n]
# Note: We do this in chunks in an effort to not hit the SQL query size limit.
for chunk in chunks(new_repo_images.keys(), 50):
existing_images = model.lookup_repository_images(namespace, repository, chunk)
for existing in existing_images:
added_images.pop(existing.docker_image_id)
logger.debug('Creating/Linking necessary images')
username = get_authenticated_user() and get_authenticated_user().username
translations = {}
for image_description in added_images.values():
model.find_create_or_link_image(image_description['id'], repo, username,
translations, storage.preferred_locations[0])
logger.debug('Created images')
track_and_log('push_repo', repo)
return make_response('Created', 201)
@ -280,7 +254,7 @@ def update_images(namespace, repository):
event.publish_event_data('docker-cli', user_data)
logger.debug('GCing repository')
num_removed = model.garbage_collect_repository(namespace, repository)
model.garbage_collect_repository(namespace, repository)
# Generate a job for each notification that has been added to this repo
logger.debug('Adding notifications for repository')
@ -288,8 +262,8 @@ def update_images(namespace, repository):
updated_tags = session.get('pushed_tags', {})
event_data = {
'updated_tags': updated_tags,
'pruned_image_count': num_removed
}
track_and_log('push_repo', repo)
spawn_notification(repo, 'repo_push', event_data)
return make_response('Updated', 204)