From 76ec168b45141a5899c1812d5bfc911f4f414daa Mon Sep 17 00:00:00 2001 From: Patrick Hulce Date: Thu, 1 Nov 2018 14:47:25 -0500 Subject: [PATCH] core(config): faster category validation (#6445) --- lighthouse-core/config/config.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lighthouse-core/config/config.js b/lighthouse-core/config/config.js index 3d3e406761d7..b7e4b4a41d8c 100644 --- a/lighthouse-core/config/config.js +++ b/lighthouse-core/config/config.js @@ -64,13 +64,18 @@ function validateCategories(categories, audits, groups) { return; } + const auditsKeyedById = new Map((audits || []).map(audit => + /** @type {[string, LH.Config.AuditDefn]} */ + ([audit.implementation.meta.id, audit]) + )); + Object.keys(categories).forEach(categoryId => { categories[categoryId].auditRefs.forEach((auditRef, index) => { if (!auditRef.id) { throw new Error(`missing an audit id at ${categoryId}[${index}]`); } - const audit = audits && audits.find(a => a.implementation.meta.id === auditRef.id); + const audit = auditsKeyedById.get(auditRef.id); if (!audit) { throw new Error(`could not find ${auditRef.id} audit for category ${categoryId}`); }