summaryrefslogtreecommitdiffstats
path: root/nova/db
diff options
context:
space:
mode:
authorChris Behrens <cbehrens@codestud.com>2012-06-26 01:59:29 +0000
committerChris Behrens <cbehrens@codestud.com>2012-06-26 02:31:41 +0000
commit3fd86122ca7085dd6112d50ea831eaf36e40e882 (patch)
tree04a54c6c862744ff1cac3f581b569a3dffe56165 /nova/db
parentca1f1d39b8ee85f55d5b656f7db946f855be5cb2 (diff)
Improve filter_scheduler performance
Add 'columns_to_join' keyword arg to instance_get_all() and have the scheduler host_manager only join 'instance_type'. It doesn't use anything else. Fixes bug 1017769 Change-Id: Ia2c0956d2453f00e26eb89d9496a32ba15d970aa
Diffstat (limited to 'nova/db')
-rw-r--r--nova/db/api.py4
-rw-r--r--nova/db/sqlalchemy/api.py15
2 files changed, 10 insertions, 9 deletions
diff --git a/nova/db/api.py b/nova/db/api.py
index e0d150506..6843412e5 100644
--- a/nova/db/api.py
+++ b/nova/db/api.py
@@ -563,9 +563,9 @@ def instance_get(context, instance_id):
return IMPL.instance_get(context, instance_id)
-def instance_get_all(context):
+def instance_get_all(context, columns_to_join=None):
"""Get all instances."""
- return IMPL.instance_get_all(context)
+ return IMPL.instance_get_all(context, columns_to_join=columns_to_join)
def instance_get_all_by_filters(context, filters, sort_key='created_at',
diff --git a/nova/db/sqlalchemy/api.py b/nova/db/sqlalchemy/api.py
index eabd03a22..8d9687120 100644
--- a/nova/db/sqlalchemy/api.py
+++ b/nova/db/sqlalchemy/api.py
@@ -1435,13 +1435,14 @@ def _build_instance_get(context, session=None):
@require_admin_context
-def instance_get_all(context):
- return model_query(context, models.Instance).\
- options(joinedload('info_cache')).\
- options(joinedload('security_groups')).\
- options(joinedload('metadata')).\
- options(joinedload('instance_type')).\
- all()
+def instance_get_all(context, columns_to_join=None):
+ if columns_to_join is None:
+ columns_to_join = ['info_cache', 'security_groups',
+ 'metadata', 'instance_type']
+ query = model_query(context, models.Instance)
+ for column in columns_to_join:
+ query = query.options(joinedload(column))
+ return query.all()
@require_context