From 68854ac3f09df6e7ad496f446500ad8df9249330 Mon Sep 17 00:00:00 2001 From: kitsunyan Date: Sun, 16 Sep 2018 20:36:49 +0300 Subject: Perform multiple AUR RPC requests for long package lists --- src/aur.nim | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) (limited to 'src/aur.nim') 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: -- cgit v1.2.3-70-g09d2