Fix tag catalog inconsistency bugs
This commit is contained in:
parent
8662122b84
commit
7264c9d12b
2 changed files with 36 additions and 14 deletions
|
|
@ -15,6 +15,7 @@ import { getComputeDeleteAddRemove } from "./refreshIndex.js";
|
|||
import {
|
||||
CodebaseIndex,
|
||||
IndexResultType,
|
||||
PathAndCacheKey,
|
||||
RefreshIndexResults,
|
||||
} from "./types.js";
|
||||
import { walkDirAsync } from "./walkDir.js";
|
||||
|
|
@ -98,6 +99,30 @@ export class CodebaseIndexer {
|
|||
return indexes;
|
||||
}
|
||||
|
||||
private totalIndexOps(results: RefreshIndexResults): number {
|
||||
return results.compute.length +
|
||||
results.del.length +
|
||||
results.addTag.length +
|
||||
results.removeTag.length;
|
||||
}
|
||||
|
||||
private singleFileIndexOps(
|
||||
results: RefreshIndexResults,
|
||||
lastUpdated: PathAndCacheKey[],
|
||||
filePath: string
|
||||
): [RefreshIndexResults, PathAndCacheKey[]] {
|
||||
const filterFn = (item: PathAndCacheKey) => item.path === filePath;
|
||||
const compute = results.compute.filter(filterFn);
|
||||
const del = results.del.filter(filterFn);
|
||||
const addTag = results.addTag.filter(filterFn);
|
||||
const removeTag = results.removeTag.filter(filterFn);
|
||||
const newResults = {
|
||||
compute, del, addTag, removeTag
|
||||
};
|
||||
const newLastUpdated = lastUpdated.filter(filterFn)
|
||||
return [newResults, newLastUpdated];
|
||||
}
|
||||
|
||||
public async refreshFile(
|
||||
file: string,
|
||||
workspaceDirs: string[],
|
||||
|
|
@ -115,26 +140,25 @@ export class CodebaseIndexer {
|
|||
const repoName = await this.ide.getRepoName(foundInDir);
|
||||
const indexesToBuild = await this.getIndexesToBuild();
|
||||
const stats = await this.ide.getFileStats([file]);
|
||||
const filePath = Object.keys(stats)[0];
|
||||
for (const index of indexesToBuild) {
|
||||
const tag = {
|
||||
directory: foundInDir,
|
||||
branch,
|
||||
artifactId: index.artifactId,
|
||||
};
|
||||
const [results, lastUpdated, markComplete] =
|
||||
const [fullResults, fullLastUpdated, markComplete] =
|
||||
await getComputeDeleteAddRemove(
|
||||
tag,
|
||||
{ ...stats },
|
||||
(filepath) => this.ide.readFile(filepath),
|
||||
repoName,
|
||||
);
|
||||
// since this is only a single file update / save we do not want to actualy remove anything, we just want to recompute for our single file
|
||||
results.removeTag = [];
|
||||
results.addTag = [];
|
||||
results.del = [];
|
||||
|
||||
const [results, lastUpdated] = this.singleFileIndexOps(
|
||||
fullResults, fullLastUpdated, filePath);
|
||||
// Don't update if nothing to update. Some of the indices might do unnecessary setup work
|
||||
if (results.compute.length === 0) {
|
||||
if (this.totalIndexOps(results) + lastUpdated.length === 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
@ -415,11 +439,7 @@ export class CodebaseIndexer {
|
|||
(filepath) => this.ide.readFile(filepath),
|
||||
repoName,
|
||||
);
|
||||
const totalOps =
|
||||
results.compute.length +
|
||||
results.del.length +
|
||||
results.addTag.length +
|
||||
results.removeTag.length;
|
||||
const totalOps = this.totalIndexOps(results);
|
||||
let completedOps = 0;
|
||||
|
||||
// Don't update if nothing to update. Some of the indices might do unnecessary setup work
|
||||
|
|
|
|||
|
|
@ -97,13 +97,15 @@ export class FullTextSearchCodebaseIndex implements CodebaseIndex {
|
|||
|
||||
// Delete
|
||||
for (const item of results.del) {
|
||||
await db.run(`
|
||||
DELETE FROM fts WHERE rowid IN (
|
||||
SELECT id FROM fts_metadata WHERE path = ? AND cacheKey = ?
|
||||
)
|
||||
`,[item.path, item.cacheKey]);
|
||||
await db.run("DELETE FROM fts_metadata WHERE path = ? AND cacheKey = ?", [
|
||||
item.path,
|
||||
item.cacheKey,
|
||||
]);
|
||||
|
||||
await db.run("DELETE FROM fts WHERE path = ?", [item.path]);
|
||||
|
||||
await markComplete([item], IndexResultType.Delete);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue