Skip to content

Commit

Permalink
Wrap call to ensure session is closed
Browse files Browse the repository at this point in the history
Otherwise there's an idle transaction left in the database (+locks)
  • Loading branch information
jdavcs committed Mar 4, 2024
1 parent 4d0b4cd commit 0468e1c
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 9 deletions.
2 changes: 1 addition & 1 deletion lib/tool_shed/webapp/controllers/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ def regenerate_statistics(self, trans, **kwd):
message = escape(kwd.get("message", ""))
status = kwd.get("status", "done")
if "regenerate_statistics_button" in kwd:
trans.app.shed_counter.generate_statistics()
trans.app.shed_counter.generate_statistics(trans.sa_session)
message = "Successfully regenerated statistics"
return trans.fill_template("/webapps/tool_shed/admin/statistics.mako", message=message, status=status)

Expand Down
5 changes: 5 additions & 0 deletions lib/tool_shed/webapp/model/mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,9 @@ def init(

result.security_agent = CommunityRBACAgent(result)
result.shed_counter = shed_statistics.ShedCounter(result)

session = result.session()
with session.begin():
result.shed_counter.generate_statistics(session)

return result
10 changes: 2 additions & 8 deletions lib/tool_shed/webapp/util/shed_statistics.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,8 @@ def __init__(self, model):
self.unique_owners = 0
self.unique_valid_tools = 0
self.workflows = 0
self.generate_statistics()

@property
def sa_session(self):
"""Returns a SQLAlchemy session"""
return self.model.context

def generate_statistics(self):
def generate_statistics(self, sa_session):
self.custom_datatypes = 0
self.deleted_repositories = 0
self.deprecated_repositories = 0
Expand All @@ -42,7 +36,7 @@ def generate_statistics(self):
self.unique_valid_tools = 0
self.workflows = 0
unique_user_ids = []
for repository in self.sa_session.scalars(select(Repository)):
for repository in sa_session.scalars(select(Repository)):
self.repositories += 1
self.total_clones += repository.times_downloaded
is_deleted = repository.deleted
Expand Down

0 comments on commit 0468e1c

Please sign in to comment.