aboutsummaryrefslogtreecommitdiff
path: root/src/aur.nim
diff options
context:
space:
mode:
authorkitsunyan2018-09-16 17:36:49 +0000
committerkitsunyan2018-09-16 17:36:49 +0000
commit68854ac3f09df6e7ad496f446500ad8df9249330 (patch)
tree0a8d8166617c9d0f48aa1a077bb6072c54d74983 /src/aur.nim
parentc0dd5e7dedf996c78617e21a7ea6bd2e3553dbfb (diff)
Perform multiple AUR RPC requests for long package lists
Diffstat (limited to 'src/aur.nim')
-rw-r--r--src/aur.nim26
1 files changed, 14 insertions, 12 deletions
diff --git a/src/aur.nim b/src/aur.nim
index 5c138b4..b729114 100644
--- a/src/aur.nim
+++ b/src/aur.nim
@@ -57,22 +57,24 @@ proc obtainPkgBaseSrcInfo(base: string, useTimeout: bool): (string, Option[strin
proc getRpcPackageInfos*(pkgs: seq[string], repo: string, useTimeout: bool):
(seq[RpcPackageInfo], Option[string]) =
- if pkgs.len == 0:
+ let dpkgs = pkgs.deduplicate
+ if dpkgs.len == 0:
(@[], none(string))
else:
+ const maxCount = 100
+ let distributed = dpkgs.distribute((dpkgs.len + maxCount - 1) /% maxCount)
withAur():
try:
- withCurl(instance):
- let url = aurUrl & "rpc/?v=5&type=info&arg[]=" & @pkgs
- .deduplicate
- .map(u => instance.escape(u))
- .foldl(a & "&arg[]=" & b)
-
- let response = performString(url, useTimeout)
- let results = parseJson(response)["results"]
- let table = lc[(x.name, x) | (y <- results, x <- parseRpcPackageInfo(y, repo)),
- (string, RpcPackageInfo)].toTable
- (lc[x | (p <- pkgs, x <- table.opt(p)), RpcPackageInfo], none(string))
+ let responses = distributed.map(pkgs => (block:
+ withCurl(instance):
+ let url = aurUrl & "rpc/?v=5&type=info&arg[]=" & @pkgs
+ .map(u => instance.escape(u))
+ .foldl(a & "&arg[]=" & b)
+ performString(url, useTimeout)))
+
+ let table = lc[(x.name, x) | (z <- responses, y <- parseJson(z)["results"],
+ x <- parseRpcPackageInfo(y, repo)), (string, RpcPackageInfo)].toTable
+ (lc[x | (p <- pkgs, x <- table.opt(p)), RpcPackageInfo], none(string))
except CurlError:
(@[], some(getCurrentException().msg))
except JsonParsingError: