From: Michael Tremer Date: Wed, 22 Jan 2025 15:17:14 +0000 (+0000) Subject: users: Fix showing total builds/build time X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6b2b565a15c9ce81981e9079051580693265efa4;p=pbs.git users: Fix showing total builds/build time Signed-off-by: Michael Tremer --- diff --git a/src/buildservice/users.py b/src/buildservice/users.py index 42c6b8e3..7920e6aa 100644 --- a/src/buildservice/users.py +++ b/src/buildservice/users.py @@ -850,26 +850,32 @@ class User(database.Base, database.BackendMixin, database.SoftDeleteMixin): # Run the query return await self.db.select_one(stmt, "count") - @lazy_property - def total_build_time(self): - res = self.db.get(""" - SELECT - SUM(jobs.finished_at - jobs.started_at) AS total_time - FROM - jobs - LEFT JOIN - builds ON jobs.build_id = builds.id - WHERE - jobs.finished_at IS NOT NULL - AND - jobs.started_at IS NOT NULL - AND - builds.owner_id = %s - """, self.id, + async def get_total_build_time(self): + """ + Returns the total build time + """ + stmt = ( + sqlalchemy + .select( + sqlalchemy.func.sum( + sqlalchemy.func.coalesce( + jobs.Job.finished_at, + sqlalchemy.func.current_timestamp() + ) + - jobs.Job.started_at, + ).label("total_build_time") + ) + .join( + builds.Build, + builds.Build.id == jobs.Job.build_id, + ) + .where( + jobs.Job.started_at != None, + builds.Build.owner == self, + ) ) - if res: - return res.total_time + return await self.db.select_one(stmt, "total_build_time") # Custom repositories diff --git a/src/templates/users/show.html b/src/templates/users/show.html index a70311ba..b12f1280 100644 --- a/src/templates/users/show.html +++ b/src/templates/users/show.html @@ -25,20 +25,24 @@