changeset 11:0d6bc7c56cd6

Group MultiCall per 100 requests
author Cédric Krier <ced@b2ck.com>
date Mon, 23 Feb 2015 16:57:51 +0100
parents c1fe07bb6955
children 1260a50b5d87
files farmhouse.py
diffstat 1 files changed, 18 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/farmhouse.py	Mon Feb 23 16:54:10 2015 +0100
+++ b/farmhouse.py	Mon Feb 23 16:57:51 2015 +0100
@@ -127,20 +127,30 @@
     return map(str.strip, packages.split(','))
 
 
+def grouper(iterable, n=100):
+    return zip(*(iter(iterable),) * n)
+
+
 @cache.memoize(timeout=2 * 60 * 60)
 def get_versions(names):
-    multicall = xmlrpc.client.MultiCall(client)
-    for name in names:
-        multicall.package_releases(name)
-    return list(multicall())
+    versions = []
+    for g_names in grouper(names):
+        multicall = xmlrpc.client.MultiCall(client)
+        for name in g_names:
+            multicall.package_releases(name)
+        versions += list(multicall())
+    return versions
 
 
 @cache.memoize(timeout=24 * 60 * 60)
 def get_urls(args):
-    multicall = xmlrpc.client.MultiCall(client)
-    for name, version in args:
-        multicall.release_urls(name, version)
-    return list(multicall())
+    urls = []
+    for g_args in grouper(args):
+        multicall = xmlrpc.client.MultiCall(client)
+        for name, version in g_args:
+            multicall.release_urls(name, version)
+        urls += list(multicall())
+    return urls
 
 
 @cache.memoize(timeout=2 * 60 * 60)