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
This commit is contained in:
parent
5964082b2c
commit
9c226e3a15
@ -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():
|
||||
|
Loading…
Reference in New Issue
Block a user