mirror of
https://github.com/adulau/hashlookup-server.git
synced 2024-11-22 01:57:08 +00:00
new: [api:stats/top] Add a new optional entry to point to get the top 100 of most queried hashes (existing and non-existing)
This commit is contained in:
parent
4419052c4f
commit
c17dbff6a6
2 changed files with 19 additions and 0 deletions
|
@ -9,6 +9,7 @@ config = configparser.ConfigParser()
|
||||||
config.read('../etc/server.conf')
|
config.read('../etc/server.conf')
|
||||||
stats = config['global'].getboolean('stats')
|
stats = config['global'].getboolean('stats')
|
||||||
stats_pubsub = config['global'].getboolean('stats_pubsub')
|
stats_pubsub = config['global'].getboolean('stats_pubsub')
|
||||||
|
stats_public = config['global'].getboolean('stats_public')
|
||||||
score = 1
|
score = 1
|
||||||
session = config['session'].getboolean('enable')
|
session = config['session'].getboolean('enable')
|
||||||
session_ttl = config['session'].get('ttl')
|
session_ttl = config['session'].get('ttl')
|
||||||
|
@ -263,6 +264,23 @@ class sessioncreate(Resource):
|
||||||
ret['info'] = rdb.get('session:{}'.format(name))
|
ret['info'] = rdb.get('session:{}'.format(name))
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
|
@api.route('/stats/top')
|
||||||
|
@api.doc(description="Return the top 100 of most queried values.")
|
||||||
|
class stattop(Resource):
|
||||||
|
def get(self):
|
||||||
|
if stats_public is False:
|
||||||
|
return {'message': 'Public statistics not enabled'}, 400
|
||||||
|
ret = {}
|
||||||
|
ret['nx'] = rdb.zrevrange("s:nx:sha1", 0, 100, withscores=True)
|
||||||
|
exist = rdb.zrevrange("s:exist:sha1", 0, 100, withscores=True)
|
||||||
|
ret['exist'] = []
|
||||||
|
for value in exist:
|
||||||
|
name = rdb.hget("h:{}".format(value[0]), "FileName")
|
||||||
|
entry = {}
|
||||||
|
entry['FileName'] = name
|
||||||
|
entry['SHA-1'] = value
|
||||||
|
ret['exist'].append(entry)
|
||||||
|
return ret
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
app.run(host='0.0.0.0')
|
app.run(host='0.0.0.0')
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
[global]
|
[global]
|
||||||
stats = yes
|
stats = yes
|
||||||
stats_pubsub = yes
|
stats_pubsub = yes
|
||||||
|
stats_public = yes
|
||||||
[session]
|
[session]
|
||||||
enable = yes
|
enable = yes
|
||||||
ttl = 86400
|
ttl = 86400
|
||||||
|
|
Loading…
Reference in a new issue