diff options
Diffstat (limited to 'webapp.py')
-rwxr-xr-x | webapp.py | 26 |
1 files changed, 11 insertions, 15 deletions
@@ -105,23 +105,19 @@ class Application: def get_details(self, package): with self.cursor() as cur: - cur.execute("SELECT id, version, architecture FROM package WHERE name = ?;", + cur.execute("SELECT p.id, version, architecture, count(filename), ifnull(sum(size), 0) FROM package AS p LEFT JOIN content ON p.id = content.pid WHERE name = ? GROUP BY p.id;", (package,)) row = cur.fetchone() - if not row: - raise NotFound() - pid, version, architecture = row - details = dict(pid=pid, - package=package, - version=version, - architecture=architecture) - cur.execute("SELECT count(filename), sum(size) FROM content WHERE pid = ?;", - (pid,)) - num_files, total_size = cur.fetchone() - if total_size is None: - total_size = 0 - details.update(dict(num_files=num_files, total_size=total_size)) - return details + if not row: + raise NotFound() + return dict( + package=package, + pid=row[0], + version=row[1], + architecture=row[2], + num_files=row[3], + total_size=row[4], + ) def get_dependencies(self, pid): with self.cursor() as cur: |