Force get_all to only make one DB call

Previously our database repository "get_all" query would lazy load child
objects.  This means for each record returned, sqlalchemy will make multiple
additional calls to the database when we build the data model.
This patch changes the query to do a joined load so that all of the required
information for the data model is pulled over at one time.
This will increase the peak memory usage on the api server during the API
call, but it should still be at a reasonable level.

Change-Id: If83c5e8cd8d13d31ad0c5130e1b8b1a1209abadb
This commit is contained in:
Michael Johnson 2017-07-10 17:40:01 -07:00
parent e37c0c7197
commit 77068905e1
1 changed files with 3 additions and 0 deletions

View File

@ -25,6 +25,7 @@ from oslo_db import exception as db_exception
from oslo_log import log as logging
from oslo_utils import excutils
from oslo_utils import uuidutils
from sqlalchemy.orm import joinedload
from octavia.common import constants as consts
from octavia.common import data_models
@ -113,6 +114,8 @@ class BaseRepository(object):
"""
deleted = filters.pop('show_deleted', True)
query = session.query(self.model_class).filter_by(**filters)
# Only make one trip to the database
query = query.options(joinedload('*'))
if not deleted:
query = query.filter(