Skip to content

Commit

Permalink
Fix SA2.0 usage in managers.history
Browse files Browse the repository at this point in the history
  • Loading branch information
jdavcs committed Oct 23, 2023
1 parent d22b1ff commit 7f1a974
Showing 1 changed file with 18 additions and 23 deletions.
41 changes: 18 additions & 23 deletions lib/galaxy/managers/histories.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
)

from sqlalchemy import (
and_,
asc,
desc,
false,
Expand All @@ -43,6 +42,11 @@
StorageCleanerManager,
)
from galaxy.managers.export_tracker import StoreExportTracker
from galaxy.model import (
History,
HistoryUserShareAssociation,
Job,
)
from galaxy.model.base import transaction
from galaxy.schema.fields import DecodedDatabaseIdField
from galaxy.schema.schema import (
Expand Down Expand Up @@ -125,7 +129,7 @@ def is_owner(
return super().is_owner(item, user)

# TODO: possibly to sharable or base
def most_recent(self, user, filters=None, current_history=None, **kwargs):
def most_recent(self, user, filters=None, current_history=None):
"""
Return the most recently update history for the user.
Expand All @@ -134,10 +138,10 @@ def most_recent(self, user, filters=None, current_history=None, **kwargs):
"""
if self.user_manager.is_anonymous(user):
return None if (not current_history or current_history.deleted) else current_history
desc_update_time = desc(self.model_class.update_time)
filters = self._munge_filters(filters, self.model_class.user_id == user.id)
# TODO: normalize this return value
return self.query(filters=filters, order_by=desc_update_time, limit=1, **kwargs).first()

filters = self._munge_filters(filters, History.user_id == user.id)
stmt = select(History).where(*filters).order_by(History.update_time.desc()).limit(1)
return self.session().scalars(stmt).first()

# .... purgable
def purge(self, history, flush=True, **kwargs):
Expand Down Expand Up @@ -217,13 +221,8 @@ def non_ready_jobs(self, history):
"""
# TODO: defer to jobModelManager (if there was one)
# TODO: genericize the params to allow other filters
jobs = (
self.session()
.query(model.Job)
.filter(model.Job.history == history)
.filter(model.Job.state.in_(model.Job.non_ready_states))
)
return jobs
stmt = select(Job).where(Job.history == history).where(Job.state.in_(Job.non_ready_states))
return self.session().scalars(stmt)

def queue_history_import(self, trans, archive_type, archive_source):
# Run job to do import.
Expand Down Expand Up @@ -341,17 +340,13 @@ def get_sharing_extra_information(
return extra

def is_history_shared_with(self, history: model.History, user: model.User) -> bool:
return bool(
self.session()
.query(self.user_share_model)
.filter(
and_(
self.user_share_model.table.c.user_id == user.id,
self.user_share_model.table.c.history_id == history.id,
)
)
.first()
stmt = (
select(HistoryUserShareAssociation.id)
.where(HistoryUserShareAssociation.user_id == user.id)
.where(HistoryUserShareAssociation.history_id == history.id)
.limit(1)
)
return bool(self.session().execute(stmt).first())

def make_members_public(self, trans, item):
"""Make the non-purged datasets in history public.
Expand Down

0 comments on commit 7f1a974

Please sign in to comment.