]> git.ipfire.org Git - pbs.git/commitdiff
Drop builds_latest view and build this in the backend
authorMichael Tremer <michael.tremer@ipfire.org>
Wed, 25 Oct 2017 15:46:59 +0000 (16:46 +0100)
committerMichael Tremer <michael.tremer@ipfire.org>
Wed, 25 Oct 2017 15:46:59 +0000 (16:46 +0100)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/buildservice/builds.py
src/buildservice/distribution.py
src/buildservice/repository.py
src/web/handlers_packages.py

index c5f995efbc2e0d6370da3471d8c4d42998291c38..4ce2c13d4d8e655624c85e51da92bca50e1bec5f 100644 (file)
@@ -111,44 +111,33 @@ 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):
-               query = "\
-                       SELECT * FROM builds \
-                               LEFT JOIN builds_latest ON builds.id = builds_latest.build_id \
-                       WHERE builds_latest.package_name = %s"
-               args = [name,]
-
-               if type:
-                       query += " AND builds_latest.build_type = %s"
-                       args.append(type)
+       def get_latest_by_name(self, name):
+               return self._get_build("SELECT builds.* FROM builds \
+                       LEFT JOIN packages ON builds.pkg_id = packages.id \
+                       WHERE packages.name = %s ORDER BY builds.time_created DESC \
+                       LIMIT 1", name)
 
-               # Get the last one only.
-               # Prefer release builds over scratch builds.
-               query += "\
-                       ORDER BY \
-                               CASE builds.type WHEN 'release' THEN 0 ELSE 1 END, \
-                               builds.time_created DESC \
-                       LIMIT 1"
+       def get_active_builds(self, name):
+               """
+                       Returns a list of all builds that are in a repository
+                       and the successors of the latest builds.
+               """
+               builds = []
 
-               res = self.db.get(query, *args)
+               for distro in self.backend.distros:
+                       for repo in distro:
+                               builds += repo.get_builds_by_name(name)
 
-               if res:
-                       return Build(self.backend, res.id, res)
-
-       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 builds:
+                       # The latest build should be at the end of the list
+                       latest_build = builds[-1]
 
-               builds = []
-               for row in self.db.query(query, *args):
-                       b = Build(self.backend, row.id, row)
-                       builds.append(b)
+                       # We will add all successors that are not broken
+                       builds += (b for b in latest_build.successors
+                               if not b.is_broken() and not b in builds)
 
-               # Sort the result. Lastest build first.
-               builds.sort(reverse=True)
+               # Order from newest to oldest
+               builds.reverse()
 
                return builds
 
@@ -949,6 +938,15 @@ class Build(base.DataObject):
 
                return self._update
 
+       @lazy_property
+       def successors(self):
+               builds = self.backend.builds._get_builds("SELECT builds.* FROM builds \
+                       LEFT JOIN packages ON builds.pkg_id = packages.id \
+                       WHERE packages.name = %s AND builds.type = %s AND \
+                       builds.time_created >= %s", self.pkg.name, "release", self.created)
+
+               return sorted(builds)
+
        @lazy_property
        def repo(self):
                res = self.db.get("SELECT repo_id FROM repositories_builds \
index eea205c65c79421abc98d6ebd3aaa527efb4d151..7d84794318b95d511e613bdf2f2220c98f7833fb 100644 (file)
@@ -53,6 +53,9 @@ class Distribution(base.DataObject):
        def __repr__(self):
                return "<%s %s>" % (self.__class__.__name__, self.name)
 
+       def __iter__(self):
+               return iter(self.repositories)
+
        @property
        def info(self):
                return {
index 8815b966187514647bc20566d0100b39ae52c02b..20dd1295adb7b889fa1805317759ad3b74c5f15b 100644 (file)
@@ -332,6 +332,17 @@ class Repository(base.DataObject):
 
                return _builds
 
+       def get_builds_by_name(self, name):
+               """
+                       Returns an ordered list of all builds that match this name
+               """
+               builds = self.backend.builds._get_builds("SELECT builds.* FROM repositories_builds \
+                       LEFT JOIN builds ON repositories_builds.build_id = builds.id \
+                       LEFT JOIN packages ON builds.pkg_id = packages.id \
+                       WHERE repositories_builds.repo_id = %s AND packages.name = %s", self.id, name)
+
+               return sorted(builds)
+
        def get_packages(self, arch):
                if arch == "src":
                        return self.backend.packages._get_packages("SELECT packages.* FROM repositories_builds \
index 00b4cd45803a688f44526914f08306a07c2d205b..9a4cbb84522d5d00825d8eacacd1c14d6ebd86e1 100644 (file)
@@ -246,7 +246,7 @@ class PackageFileViewHandler(PackageFileDownloadHandler):
 
 class PackageBuildsTimesHandler(BaseHandler):
        def get(self, name):
-               latest_build = self.pakfire.builds.get_latest_by_name(name, type="release")
+               latest_build = self.pakfire.builds.get_latest_by_name(name)
 
                # If no build with this name was found, we cannot go on.
                if not latest_build: