Skip to content
This repository was archived by the owner on May 20, 2025. It is now read-only.

Commit dc32479

Browse files
committed
Modify call in views to make ES fields optional. Further add caching for es health in handler code
1 parent b8176b6 commit dc32479

2 files changed

Lines changed: 16 additions & 11 deletions

File tree

pydat/pydat/handlers/es.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -130,12 +130,15 @@ def cluster_stats():
130130

131131

132132
def cluster_health():
133-
try:
134-
es = es_connector()
135-
except Exception as e:
136-
raise
133+
health = cache.get('cluster_health')
134+
if health is None:
135+
try:
136+
es = es_connector()
137+
except Exception as e:
138+
raise
137139

138-
health = es.cluster.health()
140+
health = es.cluster.health()
141+
cache.set('cluster_health', health, CACHE_TIME)
139142

140143
return health['status']
141144

pydat/pydat/views.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def __renderErrorPage__(request, message, data=None):
3333
return render(request, 'error.html', context=context)
3434

3535

36-
def __createRequestContext__(data=None):
36+
def __createRequestContext__(data=None, include_es=True):
3737
# Default to adding search forms to every context
3838
search_f = domain_form()
3939
pdns_f_dyn = pdns_form_dynamic()
@@ -44,14 +44,15 @@ def __createRequestContext__(data=None):
4444
'advdomain_form': advdomain_f,
4545
'pdns_form_dynamic': pdns_f_dyn,
4646
'rpdns_form_dynamic': rpdns_f_dyn,
47-
'latest_version': handler.lastVersion(),
4847
'pdns_sources': [
4948
mod_data.config
5049
for mod_data in passive.PDNS_HANDLER_MODS.values()]}
5150

52-
ctx_var['health'] = handler.cluster_health().capitalize()
53-
ctx_var['record_count'] = handler.record_count()
54-
ctx_var['last_import'] = handler.lastUpdate()
51+
if include_es:
52+
ctx_var['latest_version'] = handler.lastVersion()
53+
ctx_var['health'] = handler.cluster_health().capitalize()
54+
ctx_var['record_count'] = handler.record_count()
55+
ctx_var['last_import'] = handler.lastUpdate()
5556

5657
if data is not None:
5758
ctx_var.update(data)
@@ -115,7 +116,8 @@ def help(request):
115116
except Exception as e:
116117
helptxt = "Unable to render help text."
117118

118-
context = __createRequestContext__(data={'help': helptxt})
119+
context = __createRequestContext__(
120+
data={'help': helptxt}, include_es=False)
119121
return render(request, 'help.html', context=context)
120122

121123

0 commit comments

Comments
 (0)