diff options
| author | Boris Pavlovic <boris@pavlovic.me> | 2013-04-19 09:41:07 +0400 |
|---|---|---|
| committer | Boris Pavlovic <boris@pavlovic.me> | 2013-04-30 09:44:04 +0400 |
| commit | 48621685389a491d0519faf8fe52dc682e020c67 (patch) | |
| tree | 9dc9bca6b3f956587a9a216a3ed00f6e265f1a46 /nova/api | |
| parent | feb1b03f9c2ce222273a0f03b78d66d5525be3ae (diff) | |
Performance optimization for contrib.flavorextraspecs
In method FlavorExtraSpecsController.index():
This method calls FlavorExtraSpecsController._get_extra_specs()
that returns all extra_specs that has flavor.
In db.api layer we are returning already extra_specs as plain object,
so there is no reason to make one more time copy of extra_specs.
In method FlavorExtraSpecsController.show():
This method should return extra_spec that corresponds to specified
key and flavor_id.
Was:
Get all extra_specs by flavor_id and filter by key locally
Now:
Filter by flavor_id and key in db.
Change-Id: I4c39f5f56511e67e37482cda1b4e9771ee9c7d7d
Diffstat (limited to 'nova/api')
| -rw-r--r-- | nova/api/openstack/compute/contrib/flavorextraspecs.py | 14 |
1 files changed, 6 insertions, 8 deletions
diff --git a/nova/api/openstack/compute/contrib/flavorextraspecs.py b/nova/api/openstack/compute/contrib/flavorextraspecs.py index de68eb7d6..6e33d3603 100644 --- a/nova/api/openstack/compute/contrib/flavorextraspecs.py +++ b/nova/api/openstack/compute/contrib/flavorextraspecs.py @@ -48,10 +48,7 @@ class FlavorExtraSpecsController(object): def _get_extra_specs(self, context, flavor_id): extra_specs = db.instance_type_extra_specs_get(context, flavor_id) - specs_dict = {} - for key, value in extra_specs.iteritems(): - specs_dict[key] = value - return dict(extra_specs=specs_dict) + return dict(extra_specs=extra_specs) def _check_body(self, body): if body is None or body == "": @@ -103,10 +100,11 @@ class FlavorExtraSpecsController(object): """Return a single extra spec item.""" context = req.environ['nova.context'] authorize(context, action='show') - specs = self._get_extra_specs(context, flavor_id) - if id in specs['extra_specs']: - return {id: specs['extra_specs'][id]} - else: + try: + extra_spec = db.instance_type_extra_specs_get_item(context, + flavor_id, id) + return extra_spec + except exception.InstanceTypeExtraSpecsNotFound as e: raise exc.HTTPNotFound() def delete(self, req, flavor_id, id): |
