Skip to content

Commit

Permalink
Fix SA2.0 ORM usage in model.History.disk_size; simplify
Browse files Browse the repository at this point in the history
  • Loading branch information
jdavcs committed Sep 29, 2023
1 parent 9ac3842 commit 3142c9d
Showing 1 changed file with 11 additions and 17 deletions.
28 changes: 11 additions & 17 deletions lib/galaxy/model/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3273,23 +3273,17 @@ def disk_size(self):
all non-purged, unique datasets within it.
"""
# non-.expression part of hybrid.hybrid_property: called when an instance is the namespace (not the class)
db_session = object_session(self)
rval = db_session.query(
func.sum(
db_session.query(HistoryDatasetAssociation.dataset_id, Dataset.total_size)
.join(Dataset)
.filter(HistoryDatasetAssociation.table.c.history_id == self.id)
.filter(HistoryDatasetAssociation.purged != true())
.filter(Dataset.purged != true())
# unique datasets only
.distinct()
.subquery()
.c.total_size
)
).first()[0]
if rval is None:
rval = 0
return rval
subq = (
select(HistoryDatasetAssociation.dataset_id, Dataset.total_size)
.join(Dataset)
.where(HistoryDatasetAssociation.table.c.history_id == self.id)
.where(HistoryDatasetAssociation.purged != true())
.where(Dataset.purged != true())
.distinct() # unique datasets only
.subquery()
)
stmt = select(func.sum(subq.c.total_size))
return object_session(self).scalar(stmt) or 0

@disk_size.expression # type: ignore[no-redef]
def disk_size(cls):
Expand Down

0 comments on commit 3142c9d

Please sign in to comment.