perf(replay): threats-only by default, no duplicate first-page or summary fetch

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
Lucas RayanandClaude Sonnet 5.5 committed 2026-11-23 10:15:50 -03:00
1 parent 19bec553f4
commit 91cdb4acbf
12 files changed
+111 -23

No files matched your search

+31 -14
View File
@@ -11,6 +11,9 @@
var CAT_OK = {};
CATS.forEach(function (c) { CAT_OK[c] = 1; });
CAT_OK.ok = 1;
// category filter: '' = threats (everything but "ok", the default), 'all' = no filter, else one category
function catVal(c) { return c === 'all' || CAT_OK[c] ? c : ''; }
function catParam(c) { return c === '' ? '!ok' : c === 'all' ? '' : c; }
var STAGES = ['recon', 'probe', 'exploit', 'access', 'banned'];
var RANK = { recon: 1, probe: 2, exploit: 3, access: 4, banned: 5 };
var WEIGHT = { notfound: 1, scanner: 3, bruteforce: 4, 'ssh-fail': 2, 'ssh-probe': 3, exploit: 15, 'ssh-ok': 30, ban: 0, ok: 0 };
@@ -57,7 +60,8 @@
'rp.restart': 'Restart',
'rp.follow': 'Follow cursor',
'rp.cat': 'Category',
'rp.cat.all': 'All categories',
'rp.cat.all': 'Threats (default)',
'rp.cat.every': 'All, including legitimate traffic',
'rp.fam': 'Family',
'rp.fam.all': 'All families',
'rp.q': 'IP or country',
@@ -153,7 +157,8 @@
'rp.restart': 'Reiniciar',
'rp.follow': 'Seguir o cursor',
'rp.cat': 'Categoria',
'rp.cat.all': 'Todas as categorias',
'rp.cat.all': 'Ameaças (padrão)',
'rp.cat.every': 'Tudo, inclusive tráfego legítimo',
'rp.fam': 'Família',
'rp.fam.all': 'Todas as famílias',
'rp.q': 'IP ou país',
@@ -348,7 +353,7 @@
from = r.from; to = r.to;
tooBig = to - from > MAX_SPAN + 3600;
var cat = qget(params, 'cat');
F.cat = CAT_OK[cat] ? cat : '';
F.cat = catVal(cat);
F.fam = str(qget(params, 'fam'), 40);
F.q = str(qget(params, 'ip'), 60);
campId = str(qget(params, 'campaign'), 80);
@@ -392,6 +397,7 @@
function normStage(s) { s = String(s || '').toLowerCase(); return s === 'ban' ? 'banned' : RANK[s] ? s : ''; }
function prepare(e) {
e.t = num(e.t);
delete e._st; // prepare() also re-annotates events already in the buffer
e.ip = str(e.ip, 64);
e.cat = CAT_OK[e.cat] ? e.cat : 'notfound';
e.status = num(e.status);
@@ -436,7 +442,7 @@
function evParams(extra) {
var o = { from: Math.floor(startFrom), to: Math.ceil(to), limit: PAGE, order: 'asc' };
if (F.host) o.host = F.host;
if (F.cat) o.cat = F.cat;
if (catParam(F.cat)) o.cat = catParam(F.cat);
if (F.fam) o.fam = F.fam;
if (F.q && !/^[A-Za-z]{2}$/.test(F.q) && !/^AS?\d+$/i.test(F.q)) o.ip = F.q;
if (extra) for (var k in extra) o[k] = extra[k];
@@ -516,7 +522,7 @@
if (tooBig) { periodLoading = false; period = null; buildDerived(); return; }
var p = { from: Math.floor(from), to: Math.ceil(to) };
if (F.host) p.host = F.host;
if (F.cat) p.cat = F.cat;
if (catParam(F.cat)) p.cat = catParam(F.cat);
if (F.fam) p.fam = F.fam;
if (F.q && ipLike(F.q)) p.ip = F.q;
U.api('/api/v1/period', p).then(function (d) {
@@ -531,15 +537,24 @@
// transitions come from the period: rebuild the buffer so rows pick them up
if (tooBig) return;
if (campId && campById[campId] && !routeT && !campStarted) { campStarted = true; clock = clamp(campById[campId].first, from, to); }
if (campId || Object.keys(ipChain).length) { var c = clock; resetBuffer(c); fetchMore(); }
// a campaign link jumps and filters by IP, "only incidents" and country/ASN filters depend on the
// chains: those need a fresh buffer. Otherwise annotate what is loaded in place (a page still in
// flight is prepared against the new chains when it arrives), without downloading it again.
if (campId || only || (F.q && !ipLike(F.q))) { var c = clock; resetBuffer(c); fetchMore(); return; }
if (!buf.length) return;
ipSt = {}; resetChains();
for (var i = 0; i < buf.length; i++) prepare(buf[i]);
listDirty = true; detailDirty = true; tlDirty = true; kick();
}
function loadSummary() {
// histogram (timeline) and server locations from the summary of the same window
var my = ++summarySeq; sumDone = false;
var p = { from: Math.floor(from), to: Math.ceil(to) };
if (F.host) p.host = F.host;
U.api('/api/v1/summary', p).then(function (d) {
// same request as the shell's, so its short-lived cache serves both
var req;
if (typeof U.summary === 'function') req = U.summary(ctx);
else { var p = { from: Math.floor(from), to: Math.ceil(to) }; if (F.host) p.host = F.host; req = U.api('/api/v1/summary', p); }
req.then(function (d) {
if (!alive || my !== summarySeq || !d) return;
(d.hosts || []).forEach(function (x) { if (x && x.location && typeof x.location.lat === 'number') { var nm = str(x.name, 80); dests[nm] = { host: nm, lat: x.location.lat, lon: x.location.lon, label: str(x.location.label || nm, 60) }; } });
pushDests();
@@ -597,14 +612,15 @@
detailDirty = true; tlDirty = true; clockDirty = true;
drawStrip(); fillFam(); kick();
}
// histogram of the period: the summary timeline (all categories but plain "ok"),
// histogram of the period: the summary timeline (filtered like the events),
// else the sessions spread over their span
function buildBins() {
var span = Math.max(1, to - from), i, k;
var tl = tlData;
if (tl && tl.series && num(tl.step) > 0) {
binStep = num(tl.step); binStart = ts(tl.start);
var n0 = 0, cats = Object.keys(tl.series).filter(function (c) { return c !== 'ok'; });
// the strip counts what the filter lets through: threats (all but "ok"), everything, or one category
var n0 = 0, cats = Object.keys(tl.series).filter(function (c) { return F.cat === '' ? c !== 'ok' : F.cat === 'all' || c === F.cat; });
cats.forEach(function (c) { n0 = Math.max(n0, tl.series[c].length); });
bins = new Array(n0);
for (i = 0; i < n0; i++) { var v = 0; for (k = 0; k < cats.length; k++) v += num(tl.series[cats[k]][i]); bins[i] = v; }
@@ -735,7 +751,7 @@
hashAt = performance.now();
var x = { t: Math.floor(clock), speed: speed };
if (F.q) x.ip = F.q;
if (F.cat) x.cat = F.cat;
if (F.cat) x.cat = F.cat; // default (threats) is the absence of cat
if (F.fam) x.fam = F.fam;
if (campId) x.campaign = campId;
if (compress) x.compress = '1';
@@ -776,7 +792,8 @@
var fb = h('div', 'rp-filters');
ui.cat = h('select', 'rp-sel'); ui.cat.setAttribute('aria-label', t('rp.cat'));
ui.cat.appendChild(opt('', t('rp.cat.all')));
CATS.forEach(function (c) { ui.cat.appendChild(opt(c, t('cat.' + c))); });
ui.cat.appendChild(opt('all', t('rp.cat.every')));
['ok'].concat(CATS).forEach(function (c) { ui.cat.appendChild(opt(c, t('cat.' + c))); });
ui.cat.value = F.cat;
ui.cat.addEventListener('change', function () { F.cat = ui.cat.value; refilter(); });
ui.fam = h('select', 'rp-sel'); ui.fam.setAttribute('aria-label', t('rp.fam'));
@@ -1390,7 +1407,7 @@
var filtersLink = (linkT || q2.camp !== campId) && (q2.cat !== F.cat || q2.fam !== F.fam || q2.q !== F.q || q2.camp !== campId);
if (rangeChanged || hostNew !== F.host || filtersLink) {
from = f2; to = t2; tooBig = to - from > MAX_SPAN + 3600; F.host = hostNew;
if (filtersLink || rangeChanged) { F.cat = CAT_OK[q2.cat] ? q2.cat : ''; F.fam = q2.fam; F.q = q2.q; campId = q2.camp; campStarted = false; campIps = null; ui.cat.value = F.cat; ui.q.value = F.q; }
if (filtersLink || rangeChanged) { F.cat = catVal(q2.cat); F.fam = q2.fam; F.q = q2.q; campId = q2.camp; campStarted = false; campIps = null; ui.cat.value = F.cat; ui.q.value = F.q; }
clock = linkT && linkT >= from && linkT <= to ? linkT : (rangeChanged ? from : clamp(clock, from, to));
playing = false; ended = false; syncPlay();
tlData = null; paintChips(); loadPeriod(); loadSummary(); resetBuffer(clock); if (!tooBig) fetchMore(); kick();