Skip to content

Commit 4c53c16

Browse files
authored
Merge pull request #2056 from getappmap/index-speedups_20241008
2 parents d1ffbc8 + 087d63c commit 4c53c16

File tree

1 file changed

+19
-8
lines changed

1 file changed

+19
-8
lines changed

packages/cli/src/fulltext/FileIndex.ts

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,15 @@ import listGitProjectFiles from './listGitProjectFIles';
1313
import querySymbols from './querySymbols';
1414
import { fileNameMatchesFilterPatterns } from './fileNameMatchesFilterPatterns';
1515

16+
makeDebug.formatters.a = (v) => {
17+
return v.join(' ');
18+
};
19+
1620
const debug = makeDebug('appmap:file-index');
1721

22+
// enable to see all indexing terms for each file
23+
const debugTerms = makeDebug('appmap:file-index:terms');
24+
1825
export type FileIndexMatch = {
1926
directory: string;
2027
fileName: string;
@@ -49,7 +56,7 @@ export class FileIndex {
4956
const rows = this.database.prepare(query).all(searchExpr, limit);
5057
if (debug.enabled)
5158
for (const row of rows) {
52-
debug(`Found row ${(row as { file_name: string }).file_name}`);
59+
debug('Found row %s', (row as { file_name: string }).file_name);
5360
}
5461
return rows.map((row: any) => ({
5562
directory: row.directory,
@@ -88,7 +95,8 @@ export class FileIndex {
8895
if (options.allowSymbols) {
8996
debug('Symbol parsing is enabled.');
9097
debug(
91-
`Generic symbol parsing is ${options.allowGenericParsing ? 'enabled.' : 'disabled.'}`
98+
'Generic symbol parsing is %s',
99+
options.allowGenericParsing ? 'enabled.' : 'disabled.'
92100
);
93101
} else {
94102
debug('Symbol parsing is disabled.');
@@ -135,16 +143,17 @@ export class FileIndex {
135143
const fileNameTokens = filePath.split(path.sep);
136144

137145
try {
138-
let terms = queryKeywords(fileNameTokens).join(' ');
146+
let terms = queryKeywords(fileNameTokens);
139147

140148
if (allowSymbols) {
141149
const symbols = querySymbols(path.join(directory, filePath), allowGenericParsing);
142-
terms += ` ${queryKeywords(symbols).sort().join(' ')}`;
150+
terms = terms.concat(queryKeywords(symbols).sort());
143151
}
144152

145-
debug(`Indexing file path ${filePath} with terms ${terms}`);
153+
debug('Indexing file path %s with %d terms', filePath, terms.length);
154+
debugTerms('Terms for path %s: %a', filePath, terms);
146155

147-
this.#insert.run(directory, filePath, terms);
156+
this.#insert.run(directory, filePath, terms.join(' '));
148157
} catch (error) {
149158
console.warn(`Error indexing document ${filePath}`);
150159
console.warn(error);
@@ -194,6 +203,7 @@ const BINARY_FILE_EXTENSIONS: string[] = [
194203
'jar',
195204
'jpeg',
196205
'jpg',
206+
'js.map',
197207
'min.js',
198208
'min.css',
199209
'mkv',
@@ -229,6 +239,7 @@ const BINARY_FILE_EXTENSIONS: string[] = [
229239
'xls',
230240
'xlsx',
231241
'xz',
242+
'yarn.lock',
232243
'zip',
233244
].map((ext) => '.' + ext);
234245

@@ -271,10 +282,10 @@ export async function filterFiles(
271282
appendFile = true;
272283
if (stats.size > 50_000) {
273284
if (isDataFile(fileName)) {
274-
debug(`Skipping large data file ${fileName} with size ${stats.size}`);
285+
debug('Skipping large data file %s with size %d', fileName, stats.size);
275286
appendFile = false;
276287
} else {
277-
debug(`WARNING Large file ${fileName} with size ${stats.size}`);
288+
debug('WARNING Large file %s with size %d', fileName, stats.size);
278289
}
279290
}
280291
}

0 commit comments

Comments
 (0)