Skip to content

Commit

Permalink
Use exists for improved readability
Browse files Browse the repository at this point in the history
I double checked the performance of "exists().where(criteria)" vs.
"select(foo).where(criteria).limit(1)" with explain analyze. While the
startup cost is 40% higher for exists, the total costs are identical.
In terms of readability, "exists" is more succinct and straightforward.
  • Loading branch information
jdavcs committed Nov 14, 2023
1 parent 0aad7ba commit 75c49bf
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions lib/galaxy/managers/histories.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from sqlalchemy import (
asc,
desc,
exists,
false,
func,
select,
Expand Down Expand Up @@ -340,13 +341,12 @@ def get_sharing_extra_information(
return extra

def is_history_shared_with(self, history: model.History, user: model.User) -> bool:
stmt = (
select(HistoryUserShareAssociation.id)
stmt = select(
exists()
.where(HistoryUserShareAssociation.user_id == user.id)
.where(HistoryUserShareAssociation.history_id == history.id)
.limit(1)
)
return bool(self.session().execute(stmt).first())
return self.session().scalar(stmt)

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

0 comments on commit 75c49bf

Please sign in to comment.