Skip to content

Commit

Permalink
fix: Revert "fix: Fix caching of unparseable SQL"
Browse files Browse the repository at this point in the history
This reverts commit e81db08.
  • Loading branch information
ahtrotta committed Aug 24, 2023
1 parent 220a6de commit 384f077
Showing 1 changed file with 6 additions and 11 deletions.
17 changes: 6 additions & 11 deletions packages/scanner/src/appMapIndex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { QueryAST } from './types';
import LRUCache from 'lru-cache';

const NormalizedSQLBySQLString = new LRUCache<string, string>({ max: 10000 });
const ASTBySQLString = new LRUCache<string, QueryAST | 'parse-error'>({ max: 1000 });
const ASTBySQLString = new LRUCache<string, QueryAST>({ max: 1000 });

export default class AppMapIndex {
constructor(public appMap: AppMap) {}
Expand All @@ -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 {
Expand Down

0 comments on commit 384f077

Please sign in to comment.