From 384f07718fed9dc6b7ae84fd37563a52d4cddbe4 Mon Sep 17 00:00:00 2001 From: Adam Trotta Date: Thu, 24 Aug 2023 15:23:29 -0400 Subject: [PATCH] fix: Revert "fix: Fix caching of unparseable SQL" This reverts commit e81db08d6f6a7b661f77aa3aead5e800e15a7358. --- packages/scanner/src/appMapIndex.ts | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/packages/scanner/src/appMapIndex.ts b/packages/scanner/src/appMapIndex.ts index 3876ac7ff5..45cb1c065e 100644 --- a/packages/scanner/src/appMapIndex.ts +++ b/packages/scanner/src/appMapIndex.ts @@ -3,7 +3,7 @@ import { QueryAST } from './types'; import LRUCache from 'lru-cache'; const NormalizedSQLBySQLString = new LRUCache({ max: 10000 }); -const ASTBySQLString = new LRUCache({ max: 1000 }); +const ASTBySQLString = new LRUCache({ max: 1000 }); export default class AppMapIndex { constructor(public appMap: AppMap) {} @@ -12,17 +12,12 @@ export default class AppMapIndex { if (!event.sql) throw new Error(`${event.fqid} is not a SQL query`); const sql = this.sqlNormalized(event); - let result: QueryAST | undefined; - const cachedAST = ASTBySQLString.get(sql); - if (cachedAST === 'parse-error') { - result = undefined; - } else if (cachedAST) { - result = cachedAST; - } else { - result = parseSQL(sql); - ASTBySQLString.set(sql, result ? result : 'parse-error'); + let ast = ASTBySQLString.get(sql); + if (!ast) { + ast = parseSQL(sql); + ast ? ASTBySQLString.set(sql, ast) : ASTBySQLString.set(sql, null); } - return result; + return ast; } sqlNormalized(event: Event): string {