More efficient log updates.

This commit is contained in:
Pēteris Caune 2018-08-19 12:52:51 +03:00
parent a883fe38aa
commit ecba1eb40b
No known key found for this signature in database
GPG Key ID: E28D7679E9A9EDE2
3 changed files with 92 additions and 90 deletions

View File

@ -386,14 +386,18 @@ def status_single(request, code):
events = _get_events(check, 20)
updated = None
if len(events):
updated = events[0].created.isoformat()
updated = events[0].created.replace(tzinfo=None).isoformat()
return JsonResponse({
doc = {
"status": status,
"status_text": STATUS_TEXT_TMPL.render({"check": check}),
"events": EVENTS_TMPL.render({"check": check, "events": events}),
"updated": updated
})
}
if updated != request.GET.get("u"):
doc["events"] = EVENTS_TMPL.render({"check": check, "events": events})
return JsonResponse(doc)
@login_required

View File

@ -30,7 +30,7 @@ $(function () {
var lastUpdated = "";
adaptiveSetInterval(function() {
$.ajax({
url: statusUrl,
url: statusUrl + (lastUpdated ? "?u=" + lastUpdated : ""),
dataType: "json",
timeout: 2000,
success: function(data) {
@ -40,7 +40,7 @@ $(function () {
$("#log-status-text").text(data.status_text);
}
if (data.updated != lastUpdated) {
if (data.events) {
lastUpdated = data.updated;
$("#events").html(data.events);
switchDateFormat(lastFormat);
@ -67,7 +67,7 @@ $(function () {
prompt("Press Ctrl+C to select:", text)
});
$("#log tr.ok").on("click", function() {
$("#events").on("click", "tr.ok", function() {
$("#ping-details-body").text("Updating...");
$('#ping-details-modal').modal("show");

View File

@ -16,7 +16,6 @@
</div>
</h2>
<div id="log-container">
<table class="table" id="log">
{% for event in events %}
{% if event.n %}
@ -103,7 +102,6 @@
<a href="{% url 'hc-log' check.code %}">Show More&hellip;</a>
</p>
{% endif %}
</div>
{% else %}
<h2>Log</h2>
<div class="alert alert-info">This check has not received any pings yet.</div>