Sergey Golitsynskiy
2022-03-16 16:48:33 -04:00
parent dbbbc6c498
commit 158b9f0a70
7 changed files with 25 additions and 27 deletions
+8 -8
View File
@@ -19,7 +19,7 @@ from sqlalchemy import (
true,
)
from sqlalchemy.orm import (
eagerload,
joinedload,
undefer,
)
@@ -407,9 +407,9 @@ class HistoryContentsManager(base.SortableManager):
.query(component_class)
.filter(component_class.id.in_(id_list))
.options(undefer(component_class._metadata))
.options(eagerload("dataset.actions")) # TODO: use class attr after moving Dataset to declarative mapping.
.options(eagerload(component_class.tags))
.options(eagerload(component_class.annotations))
.options(joinedload("dataset.actions")) # TODO: use class attr after moving Dataset to declarative mapping.
.options(joinedload(component_class.tags))
.options(joinedload(component_class.annotations))
)
return {row.id: row for row in query.all()}
@@ -422,9 +422,9 @@ class HistoryContentsManager(base.SortableManager):
self._session()
.query(component_class)
.filter(component_class.id.in_(id_list))
.options(eagerload(component_class.collection))
.options(eagerload(component_class.tags))
.options(eagerload(component_class.annotations))
.options(joinedload(component_class.collection))
.options(joinedload(component_class.tags))
.options(joinedload(component_class.annotations))
)
# This will conditionally join a potentially costly job_state summary
@@ -432,7 +432,7 @@ class HistoryContentsManager(base.SortableManager):
# should really be a property of the manager class instance
if serialization_params and serialization_params.keys:
if "job_state_summary" in serialization_params.keys:
query = query.options(eagerload(component_class.job_state_summary))
query = query.options(joinedload(component_class.job_state_summary))
return {row.id: row for row in query.all()}
@@ -7,7 +7,6 @@ from sqlalchemy import (
true,
)
from sqlalchemy.orm import (
eagerload,
joinedload,
undefer,
)
@@ -264,14 +263,14 @@ class HistoryAllPublishedGrid(grids.Grid):
def build_initial_query(self, trans, **kwargs):
# TODO: Tags are still loaded one at a time, consider doing this all at once:
# - eagerload would keep everything in one query but would explode the number of rows and potentially
# - joinedload would keep everything in one query but would explode the number of rows and potentially
# result in unneeded info transferred over the wire.
# - subqueryload("tags").subqueryload("tag") would probably be better under postgres but I'd
# like some performance data against a big database first - might cause problems?
# - Pull down only username from associated User table since that is all that is used
# (can be used during search). Need join in addition to the eagerload since it is used in
# the .count() query which doesn't respect the eagerload options (could eliminate this with #5523).
# (can be used during search). Need join in addition to the joinedload since it is used in
# the .count() query which doesn't respect the joinedload options (could eliminate this with #5523).
# - Undefer average_rating column to prevent loading individual ratings per-history.
# - Eager load annotations - this causes a left join which might be inefficient if there were
# potentially many items per history (like if joining HDAs for instance) but there should only
@@ -279,7 +278,7 @@ class HistoryAllPublishedGrid(grids.Grid):
return (
trans.sa_session.query(self.model_class)
.join("user")
.options(eagerload("user").load_only("username"), eagerload("annotations"), undefer("average_rating"))
.options(joinedload("user").load_only("username"), joinedload("annotations"), undefer("average_rating"))
)
def apply_query_filter(self, trans, query, **kwargs):
@@ -685,8 +684,8 @@ class HistoryController(BaseUIController, SharableMixin, UsesAnnotations, UsesIt
user = session.query(model.User).filter_by(username=username).first()
history = (
trans.sa_session.query(model.History)
.options(eagerload("tags"))
.options(eagerload("annotations"))
.options(joinedload("tags"))
.options(joinedload("annotations"))
.filter_by(user=user, slug=slug, deleted=False)
.first()
)
@@ -5,7 +5,7 @@ from sqlalchemy import (
true,
)
from sqlalchemy.orm import (
eagerload,
joinedload,
undefer,
)
@@ -166,7 +166,7 @@ class PageAllPublishedGrid(grids.Grid):
trans.sa_session.query(self.model_class)
.join("user")
.filter(model.User.deleted == false())
.options(eagerload("user").load_only("username"), eagerload("annotations"), undefer("average_rating"))
.options(joinedload("user").load_only("username"), joinedload("annotations"), undefer("average_rating"))
)
def apply_query_filter(self, trans, query, **kwargs):
@@ -16,7 +16,7 @@ from sqlalchemy import (
true,
)
from sqlalchemy.orm import (
eagerload,
joinedload,
undefer,
)
@@ -290,7 +290,7 @@ class VisualizationAllPublishedGrid(grids.Grid):
return (
trans.sa_session.query(self.model_class)
.join("user")
.options(eagerload("user").load_only("username"), eagerload("annotations"), undefer("average_rating"))
.options(joinedload("user").load_only("username"), joinedload("annotations"), undefer("average_rating"))
)
def apply_query_filter(self, trans, query, **kwargs):
@@ -10,7 +10,6 @@ from sqlalchemy import (
desc,
)
from sqlalchemy.orm import (
eagerload,
joinedload,
lazyload,
undefer,
@@ -174,8 +173,8 @@ class StoredWorkflowAllPublishedGrid(grids.Grid):
.join("user")
.options(
lazyload("latest_workflow"),
eagerload("user").load_only("username"),
eagerload("annotations"),
joinedload("user").load_only("username"),
joinedload("annotations"),
undefer("average_rating"),
)
)
@@ -13,7 +13,7 @@ from sqlalchemy import (
null,
true,
)
from sqlalchemy.orm import eagerload
from sqlalchemy.orm import joinedload
from galaxy import (
model,
@@ -115,7 +115,7 @@ class System(BaseUIController):
model.History.update_time < cutoff_time,
)
)
.options(eagerload("datasets"))
.options(joinedload("datasets"))
)
for history in histories:
+3 -3
View File
@@ -19,7 +19,7 @@ from sqlalchemy import (
null,
true,
)
from sqlalchemy.orm import eagerload
from sqlalchemy.orm import joinedload
sys.path.insert(1, os.path.abspath(os.path.join(os.path.dirname(__file__), os.pardir, os.pardir, "lib")))
@@ -258,7 +258,7 @@ def purge_histories(app, cutoff_time, remove_from_disk, info_only=False, force_r
histories = (
app.sa_session.query(app.model.History)
.filter(and_(app.model.History.table.c.deleted == true(), app.model.History.update_time < cutoff_time))
.options(eagerload("datasets"))
.options(joinedload("datasets"))
)
else:
histories = (
@@ -270,7 +270,7 @@ def purge_histories(app, cutoff_time, remove_from_disk, info_only=False, force_r
app.model.History.update_time < cutoff_time,
)
)
.options(eagerload("datasets"))
.options(joinedload("datasets"))
)
for history in histories:
log.info("### Processing history id %d (%s)", history.id, unicodify(history.name))