diff options
author | Helmut Grohne <helmut@subdivi.de> | 2022-01-12 06:01:18 +0100 |
---|---|---|
committer | Helmut Grohne <helmut@subdivi.de> | 2022-01-12 06:01:18 +0100 |
commit | 8a05a6d8bacea0643a4967eed4cd67019ee0b6d7 (patch) | |
tree | 821693c03cec65fc72528b3f469443522ffa63d6 | |
parent | 1c9fb7df0073d143620a0f9d50974683df03c5ae (diff) | |
download | debian-dedup-8a05a6d8bacea0643a4967eed4cd67019ee0b6d7.tar.gz |
webapp.py: fuse two sql queries in get_details
-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: |