Skip to content

Commit deb3c36

Browse files
authored
Merge pull request continuedev#4587 from continuedev/dallin/cache-walkdir
Walkdir caching first pass
2 parents 0f3737d + 14db334 commit deb3c36

14 files changed

+182
-38
lines changed

core/config/loadLocalAssistants.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,14 @@ export async function getAssistantFilesFromDir(
3131
return [];
3232
}
3333

34-
const overrideIgnore = ignore()
34+
const overrideDefaultIgnores = ignore()
3535
.add(DEFAULT_IGNORE_FILETYPES.filter((t) => t !== "config.yaml"))
3636
.add(DEFAULT_IGNORE_DIRS);
3737

38-
const uris = await walkDir(dir, ide, { overrideIgnore });
38+
const uris = await walkDir(dir, ide, {
39+
overrideDefaultIgnores,
40+
source: "get assistant files",
41+
});
3942
const assistantFilePaths = uris.filter(
4043
(p) => p.endsWith(".yaml") || p.endsWith(".yml"),
4144
);

core/context/providers/FileContextProvider.ts

+8-2
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ import {
88
} from "../../";
99
import { walkDirs } from "../../indexing/walkDir";
1010
import {
11-
getUriPathBasename,
1211
getShortestUniqueRelativeUriPaths,
1312
getUriDescription,
13+
getUriPathBasename,
1414
} from "../../util/uri";
1515

1616
const MAX_SUBMENU_ITEMS = 10_000;
@@ -53,7 +53,13 @@ class FileContextProvider extends BaseContextProvider {
5353
args: LoadSubmenuItemsArgs,
5454
): Promise<ContextSubmenuItem[]> {
5555
const workspaceDirs = await args.ide.getWorkspaceDirs();
56-
const results = await walkDirs(args.ide, undefined, workspaceDirs);
56+
const results = await walkDirs(
57+
args.ide,
58+
{
59+
source: "load submenu items - file",
60+
},
61+
workspaceDirs,
62+
);
5763
const files = results.flat().slice(-MAX_SUBMENU_ITEMS);
5864
const withUniquePaths = getShortestUniqueRelativeUriPaths(
5965
files,

core/context/providers/FileTreeContextProvider.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,9 @@ class FileTreeContextProvider extends BaseContextProvider {
5050
directories: [],
5151
};
5252

53-
const uris = await walkDir(workspaceDir, extras.ide);
53+
const uris = await walkDir(workspaceDir, extras.ide, {
54+
source: "get context items - file tree",
55+
});
5456
const relativePaths = uris.map(
5557
(uri) => findUriInDirs(uri, [workspaceDir]).relativePathOrBasename,
5658
);

core/context/providers/FolderContextProvider.ts

+1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ class FolderContextProvider extends BaseContextProvider {
3636
args.ide,
3737
{
3838
onlyDirs: true,
39+
source: "load submenu items - folder",
3940
},
4041
workspaceDirs,
4142
);

core/context/providers/RepoMapContextProvider.ts

+1
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ class RepoMapContextProvider extends BaseContextProvider {
5555
args.ide,
5656
{
5757
onlyDirs: true,
58+
source: "load submenu items - repo map",
5859
},
5960
workspaceDirs,
6061
);

core/core.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ import {
4646

4747
import { isLocalAssistantFile } from "./config/loadLocalAssistants";
4848
import { shouldIgnore } from "./indexing/shouldIgnore";
49+
import { walkDirCache } from "./indexing/walkDir";
4950
import type { FromCoreProtocol, ToCoreProtocol } from "./protocol";
5051
import type { IMessenger, Message } from "./protocol/messenger";
5152

@@ -834,6 +835,7 @@ export class Core {
834835
if (!config || config.disableIndexing) {
835836
return; // TODO silent in case of commands?
836837
}
838+
walkDirCache.invalidate();
837839
if (data?.shouldClearIndexes) {
838840
const codebaseIndexer = await this.codebaseIndexerPromise;
839841
await codebaseIndexer.clearIndexes();
@@ -861,9 +863,8 @@ export class Core {
861863
// TODO - remove remaining logic for these from IDEs where possible
862864
on("files/changed", async ({ data }) => {
863865
if (data?.uris?.length) {
866+
walkDirCache.invalidate(); // safe approach for now - TODO - only invalidate on relevant changes
864867
for (const uri of data.uris) {
865-
// Listen for file changes in the workspace
866-
// URI TODO is this equality statement valid?
867868
const currentProfileUri =
868869
this.configHandler.currentProfile?.profileDescription.uri ?? "";
869870

@@ -934,6 +935,7 @@ export class Core {
934935

935936
on("files/created", async ({ data }) => {
936937
if (data?.uris?.length) {
938+
walkDirCache.invalidate();
937939
void refreshIfNotIgnored(data.uris);
938940

939941
// If it's a local assistant being created, we want to reload all assistants so it shows up in the list
@@ -947,6 +949,7 @@ export class Core {
947949

948950
on("files/deleted", async ({ data }) => {
949951
if (data?.uris?.length) {
952+
walkDirCache.invalidate();
950953
void refreshIfNotIgnored(data.uris);
951954
}
952955
});

core/indexing/CodebaseIndexer.test.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ import {
1414
} from "../test/testDir.js";
1515
import { getIndexSqlitePath } from "../util/paths.js";
1616

17+
import { localPathToUri } from "../util/pathToUri.js";
1718
import { CodebaseIndexer, PauseToken } from "./CodebaseIndexer.js";
1819
import { getComputeDeleteAddRemove } from "./refreshIndex.js";
1920
import { TestCodebaseIndex } from "./TestCodebaseIndex.js";
2021
import { CodebaseIndex } from "./types.js";
21-
import { walkDir } from "./walkDir.js";
22-
import { localPathToUri } from "../util/pathToUri.js";
22+
import { walkDir, walkDirCache } from "./walkDir.js";
2323

2424
jest.useFakeTimers();
2525

@@ -87,6 +87,10 @@ describe("CodebaseIndexer", () => {
8787
tearDownTestDir();
8888
});
8989

90+
afterEach(() => {
91+
walkDirCache.invalidate();
92+
});
93+
9094
async function refreshIndex() {
9195
const abortController = new AbortController();
9296
const abortSignal = abortController.signal;

core/indexing/CodebaseIndexer.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,9 @@ export class CodebaseIndexer {
281281
status: "indexing",
282282
};
283283
const directoryFiles = [];
284-
for await (const p of walkDirAsync(directory, this.ide)) {
284+
for await (const p of walkDirAsync(directory, this.ide, {
285+
source: "codebase indexing: refresh dirs",
286+
})) {
285287
directoryFiles.push(p);
286288
if (abortSignal.aborted) {
287289
yield {

core/indexing/walkDir.test.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
// Generated by continue
22
import fs from "fs";
33
import path from "path";
4-
import { walkDir, walkDirAsync, walkDirs } from "../indexing/walkDir";
4+
import {
5+
walkDir,
6+
walkDirAsync,
7+
walkDirCache,
8+
walkDirs,
9+
} from "../indexing/walkDir";
510
import { testIde } from "../test/fixtures";
611
import {
712
addToTestDir,
@@ -17,6 +22,7 @@ describe("walkDir functions", () => {
1722

1823
afterEach(async () => {
1924
tearDownTestDir();
25+
walkDirCache.invalidate();
2026
});
2127

2228
// describe.only("test speed", () => {

0 commit comments

Comments
 (0)