Skip to content

Commit

Permalink
Fix SA2.0 usage in managers.users
Browse files Browse the repository at this point in the history
  • Loading branch information
jdavcs committed Oct 19, 2023
1 parent 04193c7 commit 9340b20
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions lib/galaxy/managers/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -414,19 +414,20 @@ def tags_used(self, user, tag_models=None):
# get all the taggable model TagAssociations
if not tag_models:
tag_models = [v.tag_assoc_class for v in self.app.tag_handler.item_tag_assoc_info.values()]
# create a union of subqueries for each for this user - getting only the tname and user_value
all_tags_query = None
for tag_model in tag_models:
subq = self.session().query(tag_model.user_tname, tag_model.user_value).filter(tag_model.user == user)
all_tags_query = subq if all_tags_query is None else all_tags_query.union(subq)

# if nothing init'd the query, bail
if all_tags_query is None:
if not tag_models:
return []

# create a union of select statements for each tag model for this user - getting only the tname and user_value
all_tags_stmt = None
for tag_model in tag_models:
stmt = select(tag_model.user_tname, tag_model.user_value).where(tag_model.user == user)
all_tags_stmt = stmt if all_tags_stmt is None else all_tags_stmt.union(stmt)

# boil the tag tuples down into a sorted list of DISTINCT name:val strings
tags = all_tags_query.distinct().all()
tags = [(f"{name}:{val}" if val else name) for name, val in tags]
all_tags_stmt = all_tags_stmt.distinct()
tag_tuples = self.session().exectute(all_tags_stmt)
tags = [(f"{name}:{val}" if val else name) for name, val in tag_tuples]
# consider named tags while sorting
return sorted(tags, key=lambda str: re.sub("^name:", "#", str))

Expand Down

0 comments on commit 9340b20

Please sign in to comment.