# 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
</div>
{% endif %}
- {% if builder.total_build_time %}
+ {% set total_build_time = builder.get_total_build_time() %}
+ {% if total_build_time %}
<div class="level-item has-text-centered">
<div>
- <p class="heading">{{ _("Total Build Time") }}</p>
+ <p class="heading">
+ {{ _("Total Build Time") }}
+ </p>
+
<p>
- {{ format_time(builder.total_build_time) }}
+ {{ total_build_time | format_time }}
</p>
</div>
</div>