diff options
author | Donald Stufft <donald@stufft.io> | 2013-05-19 03:11:00 -0400 |
---|---|---|
committer | Donald Stufft <donald@stufft.io> | 2013-05-19 03:11:00 -0400 |
commit | 20d3a0ff55b178b9f28fcfac2e3589de177bd7e3 (patch) | |
tree | a9456feaa53931692faddbde07661e2b5a6f21d5 /store.py | |
parent | 4c0d88f2716b849841226028a5a55e8fec7b3f74 (diff) | |
download | decorator-20d3a0ff55b178b9f28fcfac2e3589de177bd7e3.tar.gz |
Add a top_packages() api endpoint to the XMRLPC interface
Diffstat (limited to 'store.py')
-rw-r--r-- | store.py | 12 |
1 files changed, 12 insertions, 0 deletions
@@ -694,6 +694,18 @@ class Store: safe_execute(cursor, sql, (name, )) return cursor.fetchone()[0] + def top_packages(self, num=None): + cursor = self.get_cursor() + sql = """SELECT name, SUM(downloads) AS downloads FROM release_files + GROUP BY name ORDER BY downloads DESC""" + if num is not None: + sql += " LIMIT %s" + safe_execute(cursor, sql, (num,)) + else: + safe_execute(cursor, sql) + + return [(p[0], p[1]) for p in cursor.fetchall()] + _Packages = FastResultRow('name stable_version') def get_packages(self): ''' Fetch the complete list of packages from the database. |