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,8 +152,15 @@ 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
|
||||||
|
@ -208,9 +215,17 @@ class lookup(Resource):
|
||||||
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