Skip to content

Commit

Permalink
Added caching for checking partials (#553)
Browse files Browse the repository at this point in the history
  • Loading branch information
vershwal authored Sep 17, 2024
1 parent 25bd4eb commit 0f0b062
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions lib/checks/090-template-syntax.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const spec = require('../specs');
const {versions, getPackageJSON} = require('../utils');
const ASTLinter = require('../ast-linter');

function processFileFunction(files, failures, rules) {
function processFileFunction(files, failures, rules, partialVerificationCache) {
// This rule is needed to find partials
// Partials are needed for a full parsing
if (!rules['mark-used-partials']) {
Expand All @@ -16,6 +16,16 @@ function processFileFunction(files, failures, rules) {
return;
}

const fileName = themeFile.file;

// Check if the file is a partial
const isPartial = fileName.startsWith('partials/');

// Skip if already cached (for partials only)
if (isPartial && partialVerificationCache.has(fileName)) {
return;
}

const astResults = linter.verify({
parsed: themeFile.parsed,
rules,
Expand All @@ -30,6 +40,11 @@ function processFileFunction(files, failures, rules) {
});
}

// Cache the result for this partial
if (isPartial) {
partialVerificationCache.set(fileName, astResults);
}

linter.partials.forEach(({normalizedName}) => {
const file = files.find(f => f.normalizedFile === `partials/${normalizedName}.hbs`);
if (file) {
Expand Down Expand Up @@ -62,15 +77,16 @@ const checkTemplateSyntax = function checkTemplateSyntax(theme, options) {
});

_.each(rulesToCheck, function (check, ruleCode) {
const partialVerificationCache = new Map();
const failures = [];
const processFile = processFileFunction(
theme.files,
failures,
{
[ruleCode]: require(`../ast-linter/rules`)[ruleCode]
}
},
partialVerificationCache
);

const linter = new ASTLinter({
partials: theme.partials,
inlinePartials: [],
Expand Down

0 comments on commit 0f0b062

Please sign in to comment.