Skip to content

Commit

Permalink
Optimize checking existing group by name
Browse files Browse the repository at this point in the history
  • Loading branch information
jdavcs committed Oct 5, 2023
1 parent 316afb0 commit fa07e87
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions lib/tool_shed/util/admin_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -438,8 +438,7 @@ def rename_group(self, trans, **kwd):
message = "Enter a valid name"
status = "error"
else:
existing_group = get_group_by_name(trans.sa_session, trans.app.model.Group, new_name)
if existing_group and existing_group.id != group.id:
if get_group_id(trans.sa_session, trans.app.model.Group, new_name) != group.id:
message = "A group with that name already exists"
status = "error"
else:
Expand Down Expand Up @@ -530,7 +529,7 @@ def create_group(self, trans, **kwd):
message = "Enter a valid name."
status = "error"
ok = False
elif get_group_by_name(trans.sa_session, trans.app.model.Group, name):
elif get_group_id(trans.sa_session, trans.app.model.Group, name):
message = (
"Group names must be unique and a group with that name already exists, so choose another name."
)
Expand Down Expand Up @@ -1017,8 +1016,8 @@ def get_role_id(session, role_model, name):
return session.scalars(stmt).first()


def get_group_by_name(session, group_model, name):
stmt = select(group_model).where(group_model.name == name).limit(1)
def get_group_id(session, group_model, name):
stmt = select(group_model.id).where(group_model.name == name).limit(1)
return session.scalars(stmt).first()


Expand Down

0 comments on commit fa07e87

Please sign in to comment.