Merge pull request #4604 from continuedev/dallin/sqlite-query-limit
Batch URIs for snippets query
This commit is contained in:
commit
0f3737d9f0
3 changed files with 53 additions and 34 deletions
|
|
@ -7,12 +7,7 @@ import {
|
|||
getQueryForFile,
|
||||
} from "../util/treeSitter";
|
||||
|
||||
import {
|
||||
DatabaseConnection,
|
||||
SqliteDb,
|
||||
tagToString,
|
||||
truncateSqliteLikePattern,
|
||||
} from "./refreshIndex";
|
||||
import { DatabaseConnection, SqliteDb, tagToString } from "./refreshIndex";
|
||||
import {
|
||||
IndexResultType,
|
||||
MarkCompleteCallback,
|
||||
|
|
@ -398,18 +393,23 @@ export class CodeSnippetsCodebaseIndex implements CodebaseIndex {
|
|||
|
||||
static async getPathsAndSignatures(
|
||||
workspaceDirs: string[],
|
||||
offset: number = 0,
|
||||
batchSize: number = 100,
|
||||
uriOffset: number = 0,
|
||||
uriBatchSize: number = 100,
|
||||
snippetOffset: number = 0,
|
||||
snippetBatchSize: number = 100,
|
||||
): Promise<{
|
||||
groupedByUri: { [path: string]: string[] };
|
||||
hasMore: boolean;
|
||||
hasMoreSnippets: boolean;
|
||||
hasMoreUris: boolean;
|
||||
}> {
|
||||
const db = await SqliteDb.get();
|
||||
await CodeSnippetsCodebaseIndex._createTables(db);
|
||||
|
||||
const likePatterns = workspaceDirs.map((dir) =>
|
||||
truncateSqliteLikePattern(`${dir}%`),
|
||||
);
|
||||
const endIndex = uriOffset + uriBatchSize;
|
||||
const uriBatch = workspaceDirs.slice(uriOffset, endIndex);
|
||||
|
||||
const likePatterns = uriBatch.map((dir) => `${dir}%`);
|
||||
|
||||
const placeholders = likePatterns.map(() => "?").join(" OR path LIKE ");
|
||||
|
||||
const query = `
|
||||
|
|
@ -420,7 +420,11 @@ export class CodeSnippetsCodebaseIndex implements CodebaseIndex {
|
|||
LIMIT ? OFFSET ?
|
||||
`;
|
||||
|
||||
const rows = await db.all(query, [...likePatterns, batchSize, offset]);
|
||||
const rows = await db.all(query, [
|
||||
...likePatterns,
|
||||
snippetBatchSize,
|
||||
snippetOffset,
|
||||
]);
|
||||
|
||||
const groupedByUri: { [path: string]: string[] } = {};
|
||||
|
||||
|
|
@ -431,8 +435,9 @@ export class CodeSnippetsCodebaseIndex implements CodebaseIndex {
|
|||
groupedByUri[path].push(signature);
|
||||
}
|
||||
|
||||
const hasMore = rows.length === batchSize;
|
||||
const hasMoreUris = endIndex < workspaceDirs.length;
|
||||
const hasMoreSnippets = rows.length === snippetBatchSize;
|
||||
|
||||
return { groupedByUri, hasMore };
|
||||
return { groupedByUri, hasMoreUris, hasMoreSnippets };
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,17 +1,17 @@
|
|||
// Generated by continue
|
||||
|
||||
import generateRepoMap from "./generateRepoMap";
|
||||
import { testIde, testLLM } from "../test/fixtures";
|
||||
import {
|
||||
setUpTestDir,
|
||||
tearDownTestDir,
|
||||
addToTestDir,
|
||||
TEST_DIR,
|
||||
} from "../test/testDir";
|
||||
import fs from "fs";
|
||||
import path from "path";
|
||||
import { getRepoMapFilePath } from "./paths";
|
||||
import { CodeSnippetsCodebaseIndex } from "../indexing/CodeSnippetsIndex";
|
||||
import { testIde, testLLM } from "../test/fixtures";
|
||||
import {
|
||||
addToTestDir,
|
||||
setUpTestDir,
|
||||
tearDownTestDir,
|
||||
TEST_DIR,
|
||||
} from "../test/testDir";
|
||||
import generateRepoMap from "./generateRepoMap";
|
||||
import { getRepoMapFilePath } from "./paths";
|
||||
|
||||
describe.skip("generateRepoMap", () => {
|
||||
beforeEach(() => {
|
||||
|
|
@ -49,7 +49,8 @@ describe.skip("generateRepoMap", () => {
|
|||
"def bar():",
|
||||
],
|
||||
},
|
||||
hasMore: false,
|
||||
hasMoreSnippets: false,
|
||||
hasMoreUris: false,
|
||||
};
|
||||
});
|
||||
|
||||
|
|
@ -108,7 +109,8 @@ describe.skip("generateRepoMap", () => {
|
|||
[path.join(TEST_DIR, "file1.js")]: [],
|
||||
[path.join(TEST_DIR, "subdir/file2.py")]: [],
|
||||
},
|
||||
hasMore: false,
|
||||
hasMoreSnippets: false,
|
||||
hasMoreUris: false,
|
||||
};
|
||||
});
|
||||
|
||||
|
|
@ -161,7 +163,8 @@ describe.skip("generateRepoMap", () => {
|
|||
[path.join(TEST_DIR, "file1.js")]: ["function foo() {}"],
|
||||
[path.join(TEST_DIR, "subdir/file2.py")]: ["def foo():"],
|
||||
},
|
||||
hasMore: false,
|
||||
hasMoreSnippets: false,
|
||||
hasMoreUris: false,
|
||||
};
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -24,7 +24,8 @@ class RepoMapGenerator {
|
|||
private allUris: string[] = [];
|
||||
private pathsInDirsWithSnippets: Set<string> = new Set();
|
||||
|
||||
private BATCH_SIZE = 100;
|
||||
private SNIPPETS_BATCH_SIZE = 100;
|
||||
private URI_BATCH_SIZE = 100;
|
||||
private REPO_MAX_CONTEXT_LENGTH_RATIO = 0.5;
|
||||
private PREAMBLE =
|
||||
"Below is a repository map. \n" +
|
||||
|
|
@ -57,13 +58,16 @@ class RepoMapGenerator {
|
|||
|
||||
if (this.options.includeSignatures) {
|
||||
// Process uris and signatures
|
||||
let offset = 0;
|
||||
let snippetOffset = 0;
|
||||
let uriOffset = 0;
|
||||
while (true) {
|
||||
const { groupedByUri, hasMore } =
|
||||
const { groupedByUri, hasMoreSnippets, hasMoreUris } =
|
||||
await CodeSnippetsCodebaseIndex.getPathsAndSignatures(
|
||||
this.allUris,
|
||||
offset,
|
||||
this.BATCH_SIZE,
|
||||
uriOffset,
|
||||
this.URI_BATCH_SIZE,
|
||||
snippetOffset,
|
||||
this.SNIPPETS_BATCH_SIZE,
|
||||
);
|
||||
// process batch
|
||||
for (const [uri, signatures] of Object.entries(groupedByUri)) {
|
||||
|
|
@ -103,10 +107,17 @@ class RepoMapGenerator {
|
|||
await this.writeToStream(content);
|
||||
}
|
||||
}
|
||||
if (!hasMore || this.contentTokens >= this.maxRepoMapTokens) {
|
||||
if (this.contentTokens >= this.maxRepoMapTokens) {
|
||||
break;
|
||||
}
|
||||
if (hasMoreSnippets) {
|
||||
snippetOffset += this.SNIPPETS_BATCH_SIZE;
|
||||
} else if (hasMoreUris) {
|
||||
snippetOffset = 0;
|
||||
uriOffset += this.URI_BATCH_SIZE;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
offset += this.BATCH_SIZE;
|
||||
}
|
||||
|
||||
// Remaining Uris just so that written repo map isn't incomplete
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue