]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Fix glance metadata SQL query performance
authorMathieu Gagné <mgagne@iweb.com>
Tue, 29 Jul 2014 15:57:15 +0000 (11:57 -0400)
committerMathieu Gagné <mgagne@iweb.com>
Tue, 29 Jul 2014 16:07:19 +0000 (12:07 -0400)
The query built to retrieve glance metadata associated to a volume
was sub-optimal: all rows of volume_glance_metadata were returned.

Fix it by properly joining the 2 tables with volume_id field.

Closes-bug: #1349936
Change-Id: Ic09414de769e71f8b8f99113838af48d8520e187

cinder/db/sqlalchemy/api.py

index 67eafbac508ed4c1627f1ee3fda39496217856a3..4f3568ffea2f0f39d06c18dcd1f0cddb79df0ef4 100644 (file)
@@ -2401,7 +2401,9 @@ def _volume_glance_metadata_get_all(context, session=None):
                         models.VolumeGlanceMetadata,
                         session=session)
     if is_user_context(context):
-        query = query.filter(models.Volume.project_id == context.project_id)
+        query = query.filter(
+            models.Volume.id == models.VolumeGlanceMetadata.volume_id,
+            models.Volume.project_id == context.project_id)
     return query.all()