⚡️ limit submenu items until you can use disk-based search, to avoid high memory use
This commit is contained in:
parent
9de68ac0cf
commit
31f04b42a4
2 changed files with 8 additions and 2 deletions
|
|
@ -8,6 +8,8 @@ import {
|
|||
import { CodeSnippetsCodebaseIndex } from "../../indexing/CodeSnippetsIndex.js";
|
||||
import { BaseContextProvider } from "../index.js";
|
||||
|
||||
const MAX_SUBMENU_ITEMS = 10_000;
|
||||
|
||||
class CodeContextProvider extends BaseContextProvider {
|
||||
static description: ContextProviderDescription = {
|
||||
title: "code",
|
||||
|
|
@ -29,13 +31,15 @@ class CodeContextProvider extends BaseContextProvider {
|
|||
async loadSubmenuItems(
|
||||
args: LoadSubmenuItemsArgs,
|
||||
): Promise<ContextSubmenuItem[]> {
|
||||
// TODO: Dynamically load submenu items based on the query
|
||||
// instead of loading everything into memory
|
||||
const tags = await args.ide.getTags("codeSnippets");
|
||||
const snippets = await Promise.all(
|
||||
tags.map((tag) => CodeSnippetsCodebaseIndex.getAll(tag)),
|
||||
);
|
||||
|
||||
const submenuItems: ContextSubmenuItem[] = [];
|
||||
for (const snippetList of snippets) {
|
||||
for (const snippetList of snippets.slice(-MAX_SUBMENU_ITEMS)) {
|
||||
submenuItems.push(...snippetList);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -8,6 +8,8 @@ import {
|
|||
import { getBasename, getLastNPathParts } from "../../util/index.js";
|
||||
import { BaseContextProvider } from "../index.js";
|
||||
|
||||
const MAX_SUBMENU_ITEMS = 10_000;
|
||||
|
||||
class FileContextProvider extends BaseContextProvider {
|
||||
static description: ContextProviderDescription = {
|
||||
title: "file",
|
||||
|
|
@ -41,7 +43,7 @@ class FileContextProvider extends BaseContextProvider {
|
|||
return args.ide.listWorkspaceContents(dir);
|
||||
}),
|
||||
);
|
||||
const files = results.flat();
|
||||
const files = results.flat().slice(-MAX_SUBMENU_ITEMS);
|
||||
return files.map((file) => {
|
||||
return {
|
||||
id: file,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue