Skip to content

Commit 0ee302b

Browse files
committed
improvement(audits): skip the sql-date-binding parse for files without drizzle-orm
check:sql-date-binding Babel-parsed all 13,941 source files in apps, packages, and scripts. A violation can only come from an `sql` tag resolved through a `drizzle-orm` import, and both the static and dynamic resolvers match the specifier as a string literal, so a file that never names the module cannot produce one. Only ~590 files do. Skipping the parse for the other 92% of bytes takes the audit from ~4.5s to ~0.8s and drops it out of the four slowest audits, taking check:audits from 6.0s to 5.3s wall and 38.0s to 32.9s serial. Output is unchanged.
1 parent df052ac commit 0ee302b

1 file changed

Lines changed: 15 additions & 1 deletion

File tree

scripts/check-sql-date-binding.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -544,6 +544,18 @@ function analyzeSource(source: string, file = 'source.ts'): FileAnalysis {
544544
return { violations }
545545
}
546546

547+
/**
548+
* Skips the parse for files that cannot bind the tag.
549+
*
550+
* `collectSqlBindings` and `isDrizzleImportCall` both match the specifier as a string literal,
551+
* so a source that never names the module yields no bindings and no violations. That is all but
552+
* ~590 of the ~13,900 scanned files, and not parsing them takes the audit from ~4.5s to ~0.8s.
553+
* An escaped specifier (`'drizzle\x2dorm'`) would evade the substring; the repo contains none.
554+
*/
555+
function mayBindDrizzleSql(source: string): boolean {
556+
return source.includes(DRIZZLE_MODULE)
557+
}
558+
547559
function collectSources(dir: string, found: string[] = []): string[] {
548560
for (const entry of readdirSync(dir, { withFileTypes: true })) {
549561
if (SKIP_DIRS.has(entry.name)) continue
@@ -560,7 +572,9 @@ function main(): void {
560572
const skipped: { file: string; parseError: string }[] = []
561573

562574
for (const file of files) {
563-
const analysis = analyzeSource(readFileSync(file, 'utf8'), file)
575+
const source = readFileSync(file, 'utf8')
576+
if (!mayBindDrizzleSql(source)) continue
577+
const analysis = analyzeSource(source, file)
564578
if (analysis.parseError) skipped.push({ file, parseError: analysis.parseError })
565579
violations.push(...analysis.violations)
566580
}

0 commit comments

Comments
 (0)