From: Michael Tremer Date: Tue, 21 Jan 2025 15:04:28 +0000 (+0000) Subject: builders: Fix showing the total build time X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=784161a9a7b826001f260e72f200472ec94272b5;p=pbs.git builders: Fix showing the total build time Signed-off-by: Michael Tremer --- diff --git a/src/buildservice/builders.py b/src/buildservice/builders.py index 893fe1ea..03c53488 100644 --- a/src/buildservice/builders.py +++ b/src/buildservice/builders.py @@ -728,25 +728,28 @@ class Builder(database.Base, database.BackendMixin, database.SoftDeleteMixin): # Stats - @functools.cached_property - def total_build_time(self): - res = self.db.get(""" - SELECT - SUM( - COALESCE(jobs.finished_at, CURRENT_TIMESTAMP) - - - jobs.started_at - ) AS t - FROM - jobs - WHERE - started_at IS NOT NULL - AND - builder_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") + ) + .where( + jobs.Job.builder == self, + jobs.Job.started_at != None, + ) ) - return res.t + return await self.db.select_one(stmt, "total_build_time") # Connections diff --git a/src/templates/builders/show.html b/src/templates/builders/show.html index 471ce435..f253f5c9 100644 --- a/src/templates/builders/show.html +++ b/src/templates/builders/show.html @@ -104,12 +104,16 @@ {% endif %} - {% if builder.total_build_time %} + {% set total_build_time = builder.get_total_build_time() %} + {% if total_build_time %}
-

{{ _("Total Build Time") }}

+

+ {{ _("Total Build Time") }} +

+

- {{ format_time(builder.total_build_time) }} + {{ total_build_time | format_time }}