has more uris approach
This commit is contained in:
parent
24c7ec82ea
commit
ba31ddae2f
2 changed files with 38 additions and 22 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 };
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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