Skip to content

Commit 5901f00

Browse files
authored
Fix code review issues: Buffer.from for indexOf, keywordsChanged flag, write chain error handling
1 parent 16036f0 commit 5901f00

3 files changed

Lines changed: 11 additions & 6 deletions

File tree

src/core/cache/fileScanCacheStore.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,12 +158,14 @@ function createFileScanCacheStore({
158158

159159
/**
160160
* Serializes write operations to prevent corruption.
161+
* Previous errors in the chain are swallowed so the next operation can proceed.
161162
* @param {function(): Promise<void>} fn
162163
* @returns {Promise<void>}
163164
*/
164165
function enqueueWrite(fn) {
165-
writeChain = writeChain.then(fn, fn);
166-
return writeChain;
166+
const next = writeChain.then(fn, () => fn());
167+
writeChain = next.catch(() => undefined);
168+
return next;
167169
}
168170

169171
return {

src/core/incremental/graphUpdater.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,10 +140,12 @@ function createGraphUpdater({
140140
}
141141
}
142142
// Add new keywords
143-
for (const kw of newKeywords) {
143+
if (newKeywords.length > 0) {
144144
keywordsChanged = true;
145-
if (!keywordMap.has(kw.keyword)) keywordMap.set(kw.keyword, []);
146-
keywordMap.get(kw.keyword).push(kw);
145+
for (const kw of newKeywords) {
146+
if (!keywordMap.has(kw.keyword)) keywordMap.set(kw.keyword, []);
147+
keywordMap.get(kw.keyword).push(kw);
148+
}
147149
}
148150

149151
// --- Update includes ---

src/core/parser/includeScanner.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,8 @@ const SMALL_FILE_THRESHOLD = 1024 * 1024; // 1 MB
363363
*/
364364
function collectIncludeDirectivesFromBuffer(buffer, basePath) {
365365
// Quick scan: if the buffer doesn't contain '*INCLUDE' at all, skip parsing entirely
366-
if (buffer.indexOf('*INCLUDE') === -1) {
366+
const INCLUDE_MARKER = Buffer.from('*INCLUDE');
367+
if (buffer.indexOf(INCLUDE_MARKER) === -1) {
367368
return { includeEntries: [], searchPaths: [basePath] };
368369
}
369370

0 commit comments

Comments
 (0)