mirror of
https://github.com/galaxyproject/galaxy.git
synced 2026-09-24 16:30:27 +08:00
Wrap call to ensure session is closed
Otherwise there's an idle transaction left in the database (+locks)
This commit is contained in:
@@ -324,7 +324,7 @@ class AdminController(BaseUIController, Admin):
|
||||
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)
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -23,14 +23,8 @@ class ShedCounter:
|
||||
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
|
||||
@@ -42,7 +36,7 @@ class ShedCounter:
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user