summaryrefslogtreecommitdiff
path: root/store.py
diff options
context:
space:
mode:
authorDonald Stufft <donald@stufft.io>2013-05-19 03:11:00 -0400
committerDonald Stufft <donald@stufft.io>2013-05-19 03:11:00 -0400
commit20d3a0ff55b178b9f28fcfac2e3589de177bd7e3 (patch)
treea9456feaa53931692faddbde07661e2b5a6f21d5 /store.py
parent4c0d88f2716b849841226028a5a55e8fec7b3f74 (diff)
downloaddecorator-20d3a0ff55b178b9f28fcfac2e3589de177bd7e3.tar.gz
Add a top_packages() api endpoint to the XMRLPC interface
Diffstat (limited to 'store.py')
-rw-r--r--store.py12
1 files changed, 12 insertions, 0 deletions
diff --git a/store.py b/store.py
index 91eb982..7d245b3 100644
--- a/store.py
+++ b/store.py
@@ -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.