Skip to content

Commit

Permalink
Do a joined query to improve performance
Browse files Browse the repository at this point in the history
When running db.list_timeseries_instances with a database containing a
large number of series instances performance can be slow due to lazy
loading running an individual query for each record when building the
data frame. Doing a join means all the records are read in a single
query, which is much more efficient when we are going to use all the
returned values anyway.

Signed-off-by: Andrew MacDonald <andrew@maccas.net>
  • Loading branch information
amacd31 committed Jan 27, 2016
1 parent 7a5846f commit dc6b13f
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion phildb/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,9 @@ def list_timeseries_instances(self, **kwargs):
query_args = self.__parse_attribute_kwargs(**kwargs)
query_args.update(initial_args)

records = session.query(TimeseriesInstance).filter_by(**query_args)
records = session.query(TimeseriesInstance).options(
joinedload(TimeseriesInstance.timeseries)
).filter_by(**query_args)
instance_list = []
for record in records:
instance = {
Expand Down

0 comments on commit dc6b13f

Please sign in to comment.