Skip to content

Commit

Permalink
Core, histories: add distinct_datasets alias for postgres in history.…
Browse files Browse the repository at this point in the history
…disk_size hybrid_property
  • Loading branch information
carlfeberhard committed Aug 6, 2015
1 parent 326175c commit b8332ca
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions lib/galaxy/model/__init__.py
Expand Up @@ -23,7 +23,7 @@
import pexpect
eggs.require('SQLAlchemy')
from sqlalchemy import and_, func, not_, or_, true
from sqlalchemy.orm import joinedload, object_session
from sqlalchemy.orm import joinedload, object_session, aliased
from sqlalchemy import join, select
from sqlalchemy.ext import hybrid

Expand Down Expand Up @@ -1260,21 +1260,23 @@ def disk_size( cls ):
# use labels here to better accrss from the query above
HistoryDatasetAssociation.table.c.history_id.label( 'history_id' ),
Dataset.total_size.label( 'dataset_size' ),
Dataset.id
Dataset.id.label( 'dataset_id' )
])
.where( HistoryDatasetAssociation.table.c.purged != true() )
.where( Dataset.table.c.purged != true() )
.select_from( hda_to_dataset_join )
# TODO: slow (in general) but most probably here - index total_size for easier sorting/distinct?
.distinct()
)
# postgres needs an alias on FROM
distinct_datasets_alias = aliased( distinct_datasets, name="datasets" )
# then, bind as property of history using the cls.id
size_query = (
select([
func.sum( distinct_datasets.c.dataset_size )
func.sum( distinct_datasets_alias.c.dataset_size )
])
.select_from( distinct_datasets )
.where( distinct_datasets.c.history_id == cls.id )
.select_from( distinct_datasets_alias )
.where( distinct_datasets_alias.c.history_id == cls.id )
)
# label creates a scalar
return size_query.label( 'disk_size' )
Expand Down

0 comments on commit b8332ca

Please sign in to comment.