Small efficiency improvement in account quotas

If you were performing an object PUT with X-Copy-From and you had
account_quotas in your pipeline but your account did not have a quota
set, then we will now avoid an unnecessary call to get_object_info().

Change-Id: I8592d4ad65e45ecf9e0557bc10ce2c2db19732e8
This commit is contained in:
Samuel Merritt 2013-10-09 12:31:26 -07:00
parent 2419df2730
commit b61add12e4

View File

@ -101,6 +101,16 @@ class AccountQuotaMiddleware(object):
copy_from = request.headers.get('X-Copy-From')
content_length = (request.content_length or 0)
account_info = get_account_info(request.environ, self.app)
if not account_info or not account_info['bytes']:
return self.app
try:
quota = int(account_info['meta'].get('quota-bytes', -1))
except ValueError:
return self.app
if quota < 0:
return self.app
if obj and copy_from:
path = '/' + ver + '/' + account + '/' + copy_from.lstrip('/')
object_info = get_object_info(request.environ, self.app, path)
@ -109,17 +119,8 @@ class AccountQuotaMiddleware(object):
else:
content_length = int(object_info['length'])
account_info = get_account_info(request.environ, self.app)
if not account_info or not account_info['bytes']:
return self.app
new_size = int(account_info['bytes']) + content_length
try:
quota = int(account_info['meta'].get('quota-bytes', -1))
except ValueError:
return self.app
if 0 <= quota < new_size:
if quota < new_size:
return HTTPRequestEntityTooLarge()
return self.app