From 9c226e3a1530a21d754ac7f1702c35f4a8e5927c Mon Sep 17 00:00:00 2001 From: Samuel Merritt Date: Thu, 10 Oct 2013 13:33:05 -0700 Subject: [PATCH] Small optimization to container_quotas When handling an object PUT with X-Copy-From, we only need to fetch the source object's size if the container has a byte quota, but we were always fetching it. Now we only fetch the size when we need it. Change-Id: I0c2c6820cdf0022ef57df5fe7dcb2dd466665a4f --- swift/common/middleware/container_quotas.py | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/swift/common/middleware/container_quotas.py b/swift/common/middleware/container_quotas.py index 17268abf2a..275c246944 100644 --- a/swift/common/middleware/container_quotas.py +++ b/swift/common/middleware/container_quotas.py @@ -85,22 +85,23 @@ class ContainerQuotaMiddleware(object): # this will hopefully 404 later return self.app - content_length = (req.content_length or 0) - copy_from = req.headers.get('X-Copy-From') - if obj and copy_from: - path = '/%s/%s/%s' % (version, account, copy_from.lstrip('/')) - object_info = get_object_info(req.environ, self.app, path) - if not object_info or not object_info['length']: - content_length = 0 - else: - content_length = int(object_info['length']) - if 'quota-bytes' in container_info.get('meta', {}) and \ 'bytes' in container_info and \ container_info['meta']['quota-bytes'].isdigit(): + content_length = (req.content_length or 0) + copy_from = req.headers.get('X-Copy-From') + if copy_from: + path = '/%s/%s/%s' % (version, account, + copy_from.lstrip('/')) + object_info = get_object_info(req.environ, self.app, path) + if not object_info or not object_info['length']: + content_length = 0 + else: + content_length = int(object_info['length']) new_size = int(container_info['bytes']) + content_length if int(container_info['meta']['quota-bytes']) < new_size: return self.bad_response(req, container_info) + if 'quota-count' in container_info.get('meta', {}) and \ 'object_count' in container_info and \ container_info['meta']['quota-count'].isdigit():