Skip to content
Snippets Groups Projects
Commit c36da748 authored by Erik Reid's avatar Erik Reid
Browse files

use parallel lookups for lg/routers

parent fc0ed2cf
No related branches found
No related tags found
No related merge requests found
import json
from flask import Blueprint, jsonify, Response
from flask import Blueprint, jsonify, Response, current_app
from inventory_provider.routes import common
......@@ -25,29 +25,25 @@ def routers(access):
status=404,
mimetype='text/html')
redis = common.get_current_redis()
def _visible(router):
if access == ACCESS_INTERNAL:
return True
return router['type'] == 'CORE'
def _routers():
i = 0
for k in redis.scan_iter('opsdb:lg:*'):
rtr = redis.get(k.decode('utf-8')).decode('utf-8')
rtr = json.loads(rtr)
i += 1
if _visible(rtr):
yield rtr
for doc in common.load_json_docs(
config_params=current_app.config['INVENTORY_PROVIDER_CONFIG'],
key_pattern='opsdb:lg:*'):
yield doc['value']
redis = common.get_current_redis()
cache_key = f'classifier-cache:lg:{access}'
result = redis.get(cache_key)
if result:
result = json.loads(result.decode('utf-8'))
else:
result = list(_routers())
result = list(filter(_visible, _routers()))
# cache this data for the next call
redis.set(cache_key, json.dumps(result).encode('utf-8'))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment