]> git.ipfire.org Git - people/jschlag/pbs.git/blobdiff - src/buildservice/builds.py
builds: Polulate cache for jobs
[people/jschlag/pbs.git] / src / buildservice / builds.py
index 281dce80b784d36f6eddeccfa3974afcd6822841..d7cbf290f8cfc37d782e5acfac5eebe3d5eff3c7 100644 (file)
@@ -48,7 +48,7 @@ class Builds(base.Object):
 
                return [self.get_by_id(b.id, b) for b in self.db.query(query)]
 
-       def get_by_user(self, user, type=None, public=None):
+       def get_by_user(self, user, type=None):
                args = []
                conditions = []
 
@@ -60,11 +60,6 @@ class Builds(base.Object):
                elif not type or type == "release":
                        pass # TODO
 
-               if public is True:
-                       conditions.append("public = 'Y'")
-               elif public is False:
-                       conditions.append("public = 'N'")
-
                query = "SELECT builds.* AS id FROM builds \
                        JOIN packages ON builds.pkg_id = packages.id"
 
@@ -80,7 +75,7 @@ class Builds(base.Object):
 
                return builds
 
-       def get_by_name(self, name, type=None, public=None, user=None, limit=None, offset=None):
+       def get_by_name(self, name, type=None, user=None, limit=None, offset=None):
                args = [name,]
                conditions = [
                        "packages.name = %s",
@@ -91,11 +86,6 @@ class Builds(base.Object):
                        args.append(type)
 
                or_conditions = []
-               if public is True:
-                       or_conditions.append("public = 'Y'")
-               elif public is False:
-                       or_conditions.append("public = 'N'")
-
                if user and not user.is_admin():
                        or_conditions.append("builds.owner_id = %s")
                        args.append(user.id)
@@ -124,7 +114,7 @@ class Builds(base.Object):
 
                return [Build(self.backend, b.id, b) for b in self.db.query(query, *args)]
 
-       def get_latest_by_name(self, name, type=None, public=None):
+       def get_latest_by_name(self, name, type=None):
                query = "\
                        SELECT * FROM builds \
                                LEFT JOIN builds_latest ON builds.id = builds_latest.build_id \
@@ -135,13 +125,6 @@ class Builds(base.Object):
                        query += " AND builds_latest.build_type = %s"
                        args.append(type)
 
-               if public is True:
-                       query += " AND builds.public = %s"
-                       args.append("Y")
-               elif public is False:
-                       query += " AND builds.public = %s"
-                       args.append("N")
-
                # Get the last one only.
                # Prefer release builds over scratch builds.
                query += "\
@@ -155,20 +138,13 @@ class Builds(base.Object):
                if res:
                        return Build(self.backend, res.id, res)
 
-       def get_active_builds(self, name, public=None):
+       def get_active_builds(self, name):
                query = "\
                        SELECT * FROM builds \
                                LEFT JOIN builds_latest ON builds.id = builds_latest.build_id \
                        WHERE builds_latest.package_name = %s AND builds.type = %s"
                args = [name, "release"]
 
-               if public is True:
-                       query += " AND builds.public = %s"
-                       args.append("Y")
-               elif public is False:
-                       query += " AND builds.public = %s"
-                       args.append("N")
-
                builds = []
                for row in self.db.query(query, *args):
                        b = Build(self.backend, row.id, row)
@@ -288,7 +264,7 @@ class Builds(base.Object):
 
                return build
 
-       def get_changelog(self, name, public=None, limit=5, offset=0):
+       def get_changelog(self, name, limit=5, offset=0):
                query = "SELECT builds.* FROM builds \
                        JOIN packages ON builds.pkg_id = packages.id \
                        WHERE \
@@ -297,13 +273,6 @@ class Builds(base.Object):
                                packages.name = %s"
                args = ["release", name,]
 
-               if public == True:
-                       query += " AND builds.public = %s"
-                       args.append("Y")
-               elif public == False:
-                       query += " AND builds.public = %s"
-                       args.append("N")
-
                query += " ORDER BY builds.time_created DESC"
 
                if limit:
@@ -356,7 +325,7 @@ class Builds(base.Object):
 
                return comments
 
-       def get_build_times_summary(self, name=None, job_type=None, arch=None):
+       def get_build_times_summary(self, name=None, arch=None):
                query = "\
                        SELECT \
                                builds_times.arch AS arch, \
@@ -377,11 +346,6 @@ class Builds(base.Object):
                        conditions.append("packages.name = %s")
                        args.append(name)
 
-               # Filter by job types.
-               if job_type:
-                       conditions.append("builds_times.job_type = %s")
-                       args.append(job_type)
-
                # Filter by arch.
                if arch:
                        conditions.append("builds_times.arch = %s")
@@ -474,23 +438,6 @@ class Build(base.DataObject):
                """
                self.db.execute("DELETE FROM builds_watchers WHERE build_id = %s", self.id)
 
-       def reset(self):
-               """
-                       Resets the whole build so it can start again (as it has never
-                       been started).
-               """
-               for job in self.jobs:
-                       job.reset()
-
-               #self.__delete_bugs()
-               self.__delete_comments()
-               self.__delete_history()
-               self.__delete_watchers()
-
-               self.state = "building"
-
-               # XXX empty log
-
        @property
        def info(self):
                """
@@ -572,13 +519,6 @@ class Build(base.DataObject):
        def date(self):
                return self.created.date()
 
-       @property
-       def public(self):
-               """
-                       Is this build public?
-               """
-               return self.data.public
-
        @lazy_property
        def size(self):
                """
@@ -784,7 +724,7 @@ class Build(base.DataObject):
                s_jobs = []
                for job in self.jobs:
                        s_jobs.append("""<a class="state_%s %s" href="/job/%s">%s</a>""" % \
-                               (job.state, job.type, job.uuid, job.arch))
+                               (job.state, "test" if job.test else "build", job.uuid, job.arch))
 
                if s_jobs:
                        s += " [%s]" % ", ".join(s_jobs)
@@ -799,22 +739,26 @@ class Build(base.DataObject):
        def critical_path(self):
                return self.pkg.critical_path
 
-       def get_jobs(self, type=None):
-               """
-                       Returns a list of jobs of this build.
-               """
-               return self.backend.jobs.get_by_build(self.id, self, type=type)
+       def _get_jobs(self, query, *args):
+               ret = []
+               for job in self.backend.jobs._get_jobs(query, *args):
+                       job.build = self
+                       ret.append(job)
+
+               return ret
 
        @lazy_property
        def jobs(self):
                """
                        Get a list of all build jobs that are in this build.
                """
-               return self.get_jobs(type="build")
+               return self._get_jobs("SELECT * FROM jobs \
+                               WHERE build_id = %s AND test IS FALSE AND deleted_at IS NULL", self.id)
 
        @property
        def test_jobs(self):
-               return self.get_jobs(type="test")
+               return self._get_jobs("SELECT * FROM jobs \
+                       WHERE build_id = %s AND test IS TRUE AND deleted_at IS NULL", self.id)
 
        @property
        def all_jobs_finished(self):
@@ -827,7 +771,7 @@ class Build(base.DataObject):
 
                return ret
 
-       def create_autojobs(self, arches=None, type="build"):
+       def create_autojobs(self, arches=None, **kwargs):
                jobs = []
 
                # Arches may be passed to this function. If not we use all arches
@@ -841,14 +785,14 @@ class Build(base.DataObject):
                        if arch == "src":
                                continue
 
-                       job = self.add_job(arch, type=type)
+                       job = self.add_job(arch, **kwargs)
                        jobs.append(job)
 
                # Return all newly created jobs.
                return jobs
 
-       def add_job(self, arch, type="build"):
-               job = self.backend.jobs.create(self, arch, type=type)
+       def add_job(self, arch, **kwargs):
+               job = self.backend.jobs.create(self, arch, **kwargs)
 
                # Add new job to cache.
                self.jobs.append(job)
@@ -908,11 +852,11 @@ class Build(base.DataObject):
        def add_comment(self, user, text, score):
                # Add the new comment to the database.
                id = self.db.execute("INSERT INTO \
-                       builds_comments(build_id, user_id, text, credit, time_created) \
+                       builds_comments(build_id, user_id, text, score, time_created) \
                        VALUES(%s, %s, %s, %s, NOW())",
                        self.id, user.id, text, score)
 
-               # Update the credit cache
+               # Update the score cache
                self.score += score
 
                # Send the new comment to all watchers and stuff.
@@ -923,16 +867,11 @@ class Build(base.DataObject):
 
        @lazy_property
        def score(self):
-               res = self.db.get("SELECT SUM(credit) AS score \
+               res = self.db.get("SELECT SUM(score) AS score \
                        FROM builds_comments WHERE build_id = %s", self.id)
 
                return res.score or 0
 
-       @property
-       def credits(self):
-               # XXX COMPAT
-               return self.score
-
        def get_commenters(self):
                users = self.db.query("SELECT DISTINCT users.id AS id FROM builds_comments \
                        JOIN users ON builds_comments.user_id = users.id \