Use req.get_param's store feature in lieu of utils.purge

This patch removes the use of utils.purge since it is no
longer needed in light of Falcon's relatively new "store"
feature, which causes the target dict to only receive the
value of the param if it is found in the request, thus
avoiding clobbering default kwarg values, which was the
original intent of utils.purge.

As a bonus, this approach is also ~40% faster.

Change-Id: I6b3d82b1f700045e50b3131902b2c7b6dc6ea13c
Implements: blueprint v1-obvious-optimizations
This commit is contained in:
kgriffs 2013-08-14 17:04:01 -05:00
parent 14f631fca0
commit b2ad8f082e
3 changed files with 16 additions and 21 deletions

View File

@ -54,11 +54,3 @@ def to_json(obj):
:param obj: a JSON-serializable object
"""
return json.dumps(obj, ensure_ascii=False)
def purge(src):
"""Returns a copy of a dict, excluding any keys set to `None`.
:param src: a dictionary-like object to copy
"""
return dict([(k, v) for k, v in src.items() if v is not None])

View File

@ -75,13 +75,14 @@ class CollectionResource(object):
def _get(self, req, project_id, queue_name):
uuid = req.get_header('Client-ID', required=True)
# TODO(kgriffs): Optimize
kwargs = utils.purge({
'marker': req.get_param('marker'),
'limit': req.get_param_as_int('limit'),
'echo': req.get_param_as_bool('echo'),
'include_claimed': req.get_param_as_bool('include_claimed'),
})
kwargs = {}
# NOTE(kgriffs): This syntax ensures that
# we don't clobber default values with None.
req.get_param('marker', store=kwargs)
req.get_param_as_int('limit', store=kwargs)
req.get_param_as_bool('echo', store=kwargs)
req.get_param_as_bool('include_claimed', store=kwargs)
try:
validate.message_listing(**kwargs)

View File

@ -93,12 +93,14 @@ class CollectionResource(object):
self.queue_controller = queue_controller
def on_get(self, req, resp, project_id):
# TODO(kgriffs): Optimize
kwargs = utils.purge({
'marker': req.get_param('marker'),
'limit': req.get_param_as_int('limit'),
'detailed': req.get_param_as_bool('detailed'),
})
kwargs = {}
# NOTE(kgriffs): This syntax ensures that
# we don't clobber default values with None.
req.get_param('marker', store=kwargs)
req.get_param_as_int('limit', store=kwargs)
req.get_param_as_bool('detailed', store=kwargs)
try:
validate.queue_listing(**kwargs)