From c470201fd8335a26c17d094839accd8352d07238 Mon Sep 17 00:00:00 2001 From: Alexandre Dulaunoy Date: Wed, 1 Sep 2021 21:36:39 +0200 Subject: [PATCH] fix: [api:md5/sha1] large set of parents are now limited and give a random selection TODO: mainly empty files and similar - warning-lists should be added --- bin/server.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/bin/server.py b/bin/server.py index 90d5f43..0ae0d71 100644 --- a/bin/server.py +++ b/bin/server.py @@ -114,7 +114,12 @@ class lookup(Resource): h['ProductCode'] = rdb.hgetall("h-ProductCode:{}".format(h['ProductCode'])) if rdb.exists("p:{}".format(sha1)): parents = [] - for parent in rdb.smembers("p:{}".format(sha1)): + card = rdb.scard("p:{}".format(sha1)) + if card <= 15: + p = rdb.smembers("p:{}".format(sha1)) + else: + p = rdb.srandmember("p:{}".format(sha1), number=10) + for parent in p: parent_details = rdb.hgetall("h:{}".format(parent)) parents.append(parent_details) h['parents'] = parents @@ -162,7 +167,13 @@ class lookup(Resource): h['ProductCode'] = rdb.hgetall("h-ProductCode:{}".format(h['ProductCode'])) if rdb.exists("p:{}".format(k)): parents = [] - for parent in rdb.smembers("p:{}".format(k)): + card = rdb.scard("p:{}".format(k)) + if card <= 15: + p = rdb.smembers("p:{}".format(k)) + else: + p = [] + p = rdb.srandmember("p:{}".format(sha1), number=10) + for parent in p: parent_details = rdb.hgetall("h:{}".format(parent)) parents.append(parent_details) h['parents'] = parents