Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scanner does not rescan #1330

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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