Alcove CMS
Ru

Part V, Inspection

The debug view

Outlines, timings and SQL for every alcove, behind a key.

With a debug_key in site.yaml, a visitor whose alcove_debug cookie holds that key sees every page rendered on request, with every alcove outlined in blue and every tile in orange. Nobody else sees any difference.

A button on each outline opens the alcove's source, its row count, the tile that matched, its cache setting, the time spent in it and in its SQL, the SQL text, and any problem found while rendering. A button at the top left shows the time of the whole page and the slowest alcoves.

On this site the key is public and the View debug button in the header sets the cookie.

Live result This page is rendered on request.

Switch the debug view on, then press the small i on this box to see its query, rows and timing.

GenreBooksOn the shelf
novel75
novella32
gothic21

Source the files behind the result above

content/site.yaml (excerpt)

debug_key: open-house-alcove-7f3c9a2d

content/alcoves/debugswitch/blueprint.html

<button class="debug-switch" type="button" data-debug-key="{{ key }}" aria-pressed="false">View debug</button>

content/assets/js/site.b3f450fa.js

(function () {
  var cookie = 'alcove_debug';
  var on = document.cookie.split(/;\s*/).some(function (c) {
    return c.indexOf(cookie + '=') === 0 && c.length > cookie.length + 1;
  });
  var buttons = document.querySelectorAll('[data-debug-key]');
  for (var i = 0; i < buttons.length; i++) {
    var b = buttons[i];
    b.textContent = on ? 'Leave debug' : 'View debug';
    b.setAttribute('aria-pressed', on ? 'true' : 'false');
    b.addEventListener('click', function (e) {
      var key = e.currentTarget.getAttribute('data-debug-key');
      if (on) {
        document.cookie = cookie + '=; path=/; max-age=0; SameSite=Lax';
      } else {
        document.cookie = cookie + '=' + key + '; path=/; max-age=7200; SameSite=Lax';
      }
      location.reload();
    });
  }
  if (on) document.documentElement.className += ' in-debug';
})();

(function () {
  var pres = document.querySelectorAll('pre[data-fetch]');
  for (var i = 0; i < pres.length; i++) {
    (function (pre) {
      var x = new XMLHttpRequest();
      x.open('GET', pre.getAttribute('data-fetch'));
      x.onload = function () {
        pre.textContent = x.status === 200 ? x.responseText : 'HTTP ' + x.status;
      };
      x.onerror = function () { pre.textContent = 'request failed'; };
      x.send();
    })(pres[i]);
  }

  var marks = document.querySelectorAll('pre[data-markup]');
  for (var j = 0; j < marks.length; j++) {
    var found = document.querySelectorAll(marks[j].getAttribute('data-markup'));
    var out = [];
    for (var k = 0; k < found.length; k++) out.push(found[k].outerHTML);
    marks[j].textContent = out.join('\n') || '(nothing matched)';
  }
})();

content/alcoves/demo_genres/alcove.yaml

query: |
  SELECT genre, count(*) AS books, sum(available) AS on_shelf
  FROM books
  GROUP BY genre
  ORDER BY books DESC