From 75c49bf6e2b1f5875ad71329383c994ac670d0c2 Mon Sep 17 00:00:00 2001 From: John Davis Date: Tue, 14 Nov 2023 14:28:29 -0500 Subject: [PATCH] Use `exists` for improved readability 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. --- lib/galaxy/managers/histories.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/galaxy/managers/histories.py b/lib/galaxy/managers/histories.py index 5c0b62e1a08a..99a7c70d80ff 100644 --- a/lib/galaxy/managers/histories.py +++ b/lib/galaxy/managers/histories.py @@ -18,6 +18,7 @@ from sqlalchemy import ( asc, desc, + exists, false, func, select, @@ -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.