changeset 8:53beb68f5707

Use MultiCall for xmlrpc requests
author Cédric Krier <ced@b2ck.com>
date Mon, 23 Feb 2015 11:19:47 +0100
parents 3a9173c3110a
children 57028de987ac
files farmhouse.py
diffstat 1 files changed, 18 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/farmhouse.py	Mon Feb 23 00:36:06 2015 +0100
+++ b/farmhouse.py	Mon Feb 23 11:19:47 2015 +0100
@@ -83,13 +83,16 @@
 def render_atom(packages, title=None):
     packages = sorted(packages)
     releases = []
-    for package in packages:
-        predicate = VersionPredicate(package)
-        versions = get_versions(predicate.name)
-        for version in versions:
+    predicates = [VersionPredicate(p) for p in packages]
+    all_versions = get_versions((p.name for p in predicates))
+    all_urls = get_urls(((p.name, v)
+            for p, versions in zip(predicates, all_versions)
+            for v in versions))
+    for predicate, versions in zip(predicates, all_versions):
+        for version, urls in zip(versions, all_urls):
             if not predicate.satisfied_by(version):
                 continue
-            for url in get_urls(predicate.name, version):
+            for url in urls:
                 releases.append(Release(predicate.name, version, url))
     context = {}
     if not title:
@@ -107,13 +110,19 @@
 
 
 @cache.memoize(timeout=2 * 60 * 60)
-def get_versions(name):
-    return client.package_releases(name)
+def get_versions(names):
+    multicall = xmlrpc.client.MultiCall(client)
+    for name in names:
+        multicall.package_releases(name)
+    return list(multicall())
 
 
 @cache.memoize(timeout=24 * 60 * 60)
-def get_urls(name, version):
-    return client.release_urls(name, version)
+def get_urls(args):
+    multicall = xmlrpc.client.MultiCall(client)
+    for name, version in args:
+        multicall.release_urls(name, version)
+    return list(multicall())
 
 
 @cache.memoize(timeout=2 * 60 * 60)