]> git.ipfire.org Git - pbs.git/commitdiff
jobs: Move estimated build time view into code
authorMichael Tremer <michael.tremer@ipfire.org>
Tue, 6 Jun 2023 16:12:28 +0000 (16:12 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Tue, 6 Jun 2023 16:12:28 +0000 (16:12 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/buildservice/jobs.py
src/database.sql

index a98433208c52c469ce4caec19d85c2e037144b9e..e8c56d4d88e730fd00ed02df89f0fdda370e0da4 100644 (file)
@@ -28,6 +28,37 @@ class Jobs(base.Object):
        connections = {}
 
        def init(self):
+               self.db.execute("""
+                       CREATE TEMPORARY VIEW package_estimated_build_times AS
+                               SELECT
+                                       packages.name,
+                                       jobs.arch,
+                                       AVG(
+                                               jobs.finished_at - jobs.started_at
+                                       ) AS build_time
+                               FROM
+                                       jobs
+                               LEFT JOIN
+                                       builds ON jobs.build_id = builds.id
+                               LEFT JOIN
+                                       packages ON builds.pkg_id = packages.id
+                               WHERE
+                                       jobs.deleted_at IS NULL
+                               AND
+                                       jobs.started_at IS NOT NULL
+                               AND
+                                       jobs.finished_at IS NOT NULL
+                               AND
+                                       jobs.failed IS FALSE
+                               AND
+                                       builds.test IS FALSE
+                               AND
+                                       jobs.finished_at >= (CURRENT_TIMESTAMP - '180 days'::interval)
+                               GROUP BY
+                                       packages.name,
+                                       jobs.arch
+               """)
+
                # Setup queue
                self.queue = Queue(self.backend)
 
index 69935a27864cfd4c5829da8f06df7607de8146fa..a5e18b9d46c7b334927c320e2a80d5490be4efa1 100644 (file)
@@ -602,6 +602,31 @@ CREATE SEQUENCE public.mirrors_id_seq
 ALTER SEQUENCE public.mirrors_id_seq OWNED BY public.mirrors.id;
 
 
+--
+-- Name: package_files; Type: TABLE; Schema: public; Owner: -
+--
+
+CREATE TABLE public.package_files (
+    pkg_id integer NOT NULL,
+    path text NOT NULL,
+    size bigint NOT NULL,
+    config boolean DEFAULT false NOT NULL,
+    mode integer NOT NULL,
+    uname text NOT NULL,
+    gname text NOT NULL,
+    ctime timestamp without time zone NOT NULL,
+    mtime timestamp without time zone NOT NULL,
+    digest_sha2_512 bytea,
+    digest_sha2_256 bytea,
+    digest_blake2b512 bytea,
+    digest_blake2s256 bytea,
+    digest_sha3_512 bytea,
+    digest_sha3_256 bytea,
+    mimetype text,
+    capabilities text
+);
+
+
 --
 -- Name: packages; Type: TABLE; Schema: public; Owner: -
 --
@@ -642,53 +667,6 @@ CREATE TABLE public.packages (
 );
 
 
---
--- Name: package_estimated_build_times; Type: VIEW; Schema: public; Owner: -
---
-
-CREATE VIEW public.package_estimated_build_times AS
- SELECT packages.name,
-    jobs.arch,
-    avg((jobs.finished_at - jobs.started_at)) AS build_time
-   FROM ((public.jobs
-     LEFT JOIN public.builds ON ((jobs.build_id = builds.id)))
-     LEFT JOIN public.packages ON ((builds.pkg_id = packages.id)))
-  WHERE ((jobs.deleted_at IS NULL) AND (jobs.started_at IS NOT NULL) AND (jobs.finished_at IS NOT NULL) AND (jobs.failed IS FALSE) AND (builds.test IS FALSE))
-  GROUP BY packages.name, jobs.arch;
-
-
---
--- Name: VIEW package_estimated_build_times; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON VIEW public.package_estimated_build_times IS 'Should add this later: AND jobs.time_finished >= (CURRENT_TIMESTAMP - ''180 days''::interval)';
-
-
---
--- Name: package_files; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.package_files (
-    pkg_id integer NOT NULL,
-    path text NOT NULL,
-    size bigint NOT NULL,
-    config boolean DEFAULT false NOT NULL,
-    mode integer NOT NULL,
-    uname text NOT NULL,
-    gname text NOT NULL,
-    ctime timestamp without time zone NOT NULL,
-    mtime timestamp without time zone NOT NULL,
-    digest_sha2_512 bytea,
-    digest_sha2_256 bytea,
-    digest_blake2b512 bytea,
-    digest_blake2s256 bytea,
-    digest_sha3_512 bytea,
-    digest_sha3_256 bytea,
-    mimetype text,
-    capabilities text
-);
-
-
 --
 -- Name: package_search_index_generator; Type: VIEW; Schema: public; Owner: -
 --