mirror of
https://github.com/adulau/hashlookup-server.git
synced 2024-11-21 17:47:06 +00:00
new: [server/api] improved children handling - if too many children are
returned it's stripped - and a sample is extracted
This commit is contained in:
parent
0357542bbd
commit
add29e6ca3
1 changed files with 32 additions and 9 deletions
|
@ -1,4 +1,4 @@
|
||||||
version = "1.1"
|
version = "1.2"
|
||||||
from flask import Flask, url_for, send_from_directory, render_template, make_response, request
|
from flask import Flask, url_for, send_from_directory, render_template, make_response, request
|
||||||
from flask_restx import Resource, Api, reqparse
|
from flask_restx import Resource, Api, reqparse
|
||||||
import redis
|
import redis
|
||||||
|
@ -152,11 +152,18 @@ class lookup(Resource):
|
||||||
h['parents'] = parents
|
h['parents'] = parents
|
||||||
if rdb.exists("c:{}".format(sha1)):
|
if rdb.exists("c:{}".format(sha1)):
|
||||||
children = []
|
children = []
|
||||||
for child in rdb.smembers("c:{}".format(sha1)):
|
card = rdb.scard("c:{}".format(sha1))
|
||||||
children.append(child)
|
if card <= 15:
|
||||||
|
c = rdb.smembers("c:{}".format(sha1))
|
||||||
|
else:
|
||||||
|
c = rdb.srandmember("c:{}".format(sha1), number=10)
|
||||||
|
h['hashlookup:children-total'] = card
|
||||||
|
for child in c:
|
||||||
|
child_details = rdb.hgetall("h:{}".format(child))
|
||||||
|
children.append(child_details)
|
||||||
h['children'] = children
|
h['children'] = children
|
||||||
h = calculate_trust(hobject=h)
|
h = calculate_trust(hobject=h)
|
||||||
return h
|
return h
|
||||||
|
|
||||||
@api.route('/lookup/sha1/<string:sha1>')
|
@api.route('/lookup/sha1/<string:sha1>')
|
||||||
@api.doc(description="Lookup SHA-1.")
|
@api.doc(description="Lookup SHA-1.")
|
||||||
|
@ -205,12 +212,20 @@ class lookup(Resource):
|
||||||
for parent in p:
|
for parent in p:
|
||||||
parent_details = rdb.hgetall("h:{}".format(parent))
|
parent_details = rdb.hgetall("h:{}".format(parent))
|
||||||
parents.append(parent_details)
|
parents.append(parent_details)
|
||||||
h['parents'] = parents
|
h['parents'] = parents
|
||||||
if rdb.exists("c:{}".format(k)):
|
if rdb.exists("c:{}".format(k)):
|
||||||
children = []
|
children = []
|
||||||
for child in rdb.smembers("c:{}".format(k)):
|
card = rdb.scard("c:{}".format(k))
|
||||||
children.append(child)
|
if card <= 15:
|
||||||
|
c = rdb.smembers("c:{}".format(k))
|
||||||
|
else:
|
||||||
|
c = rdb.srandmember("c:{}".format(k), number=10)
|
||||||
|
h['hashlookup:children-total'] = card
|
||||||
|
for child in c:
|
||||||
|
child_details = rdb.hgetall("h:{}".format(child))
|
||||||
|
children.append(child_details)
|
||||||
h['children'] = children
|
h['children'] = children
|
||||||
|
|
||||||
h = calculate_trust(hobject=h)
|
h = calculate_trust(hobject=h)
|
||||||
return h
|
return h
|
||||||
|
|
||||||
|
@ -268,9 +283,17 @@ class lookup(Resource):
|
||||||
h['parents'] = parents
|
h['parents'] = parents
|
||||||
if rdb.exists("c:{}".format(sha1)):
|
if rdb.exists("c:{}".format(sha1)):
|
||||||
children = []
|
children = []
|
||||||
for child in rdb.smembers("c:{}".format(sha1)):
|
card = rdb.scard("c:{}".format(sha1))
|
||||||
children.append(child)
|
if card <= 15:
|
||||||
|
c = rdb.smembers("c:{}".format(sha1))
|
||||||
|
else:
|
||||||
|
c = rdb.srandmember("c:{}".format(sha1), number=10)
|
||||||
|
h['hashlookup:children-total'] = card
|
||||||
|
for child in c:
|
||||||
|
child_details = rdb.hgetall("h:{}".format(child))
|
||||||
|
children.append(child_details)
|
||||||
h['children'] = children
|
h['children'] = children
|
||||||
|
|
||||||
h = calculate_trust(hobject=h)
|
h = calculate_trust(hobject=h)
|
||||||
return h
|
return h
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue