* 🎨 refactor out react context * 🎨 refactor local storage * 🎨 refactor IdeMessenger * 🔥 removing unused files * 🚚 move scripts * ✅ setup VSCode integration testing * 🎨 fix test-related stuff * 🚧 testing * 🎨 tweak terminal cmd+L * 🧑💻 install biome in core * 🎨 run biome check on core * 🎨 run biome check in vscode * 🎨 run biome check in binary * 🧑💻 global biome config * 🎨 run biome check on core * 🎨 run biome check in vscode * 🎨 fix a few biome warnings * 🚧 WIP on protocols * 🚧 progress, organizing, about to remove webviewCore protocol * 🚧 now running * 🚧 move indexing code to core * 🚧 WIP on JetBrains indexing implementation * 🎨 finish listDir * 🚧 gui fixes * 🏷️ update IMessenger.on return type * 🐛 fix jetbrains types + IDE detection * 🧑💻 set up debugging for binary with TcpMessenger * 👷 fix prepackage.js * 🧑💻 turn off debug mode for intellij * 🐛 merge fixes * 🐛 fixes after refactor * 🐛 merge fixes * 💄 increase font size in JB * 🔀 merge changes * 🩹 small fixes * 🐛 fix jetbrains build * 🩹 more jetbrains fixes * 🎨 jetbrains improvements * 🐛 fix lancedb prob in jetbrains build * 👷 update jetbrains build process * ✨ intellij problems context provider * 👷 add script utils file * 💚 fix jetbrains build regression * 🎨 dynamic import transformers.js * 🩹 small jetbrains updates * ✨ folder context provider in jetbrains * 🎨 many more jetbrains improvements * 🔀 merge fixes * ⚡️ small improvements * 🎨 tell users transformers.js not supported * 🎨 trial updates * 📝 update jetbrains readmej * ⚡️ only use smaller context for local autocomplete models * ⚡️ improve bracket filter * ✨ global .continue/.prompts folder * 💄 improved model setup process * 🥅 display VSCode req errs
82 lines
1.9 KiB
TypeScript
82 lines
1.9 KiB
TypeScript
import { open } from "sqlite";
|
|
import sqlite3 from "sqlite3";
|
|
import { DatabaseConnection } from "../indexing/refreshIndex.js";
|
|
import { getTabAutocompleteCacheSqlitePath } from "../util/paths.js";
|
|
|
|
export class AutocompleteLruCache {
|
|
private static capacity = 1000;
|
|
|
|
db: DatabaseConnection;
|
|
|
|
constructor(db: DatabaseConnection) {
|
|
this.db = db;
|
|
}
|
|
|
|
static async get(): Promise<AutocompleteLruCache> {
|
|
const db = await open({
|
|
filename: getTabAutocompleteCacheSqlitePath(),
|
|
driver: sqlite3.Database,
|
|
});
|
|
|
|
await db.run(`
|
|
CREATE TABLE IF NOT EXISTS cache (
|
|
key TEXT PRIMARY KEY,
|
|
value TEXT NOT NULL,
|
|
timestamp INTEGER NOT NULL
|
|
)
|
|
`);
|
|
|
|
return new AutocompleteLruCache(db);
|
|
}
|
|
|
|
async get(key: string): Promise<string | undefined> {
|
|
const result = await this.db.get(
|
|
"SELECT value FROM cache WHERE key = ?",
|
|
key,
|
|
);
|
|
|
|
if (result) {
|
|
await this.db.run(
|
|
"UPDATE cache SET timestamp = ? WHERE key = ?",
|
|
Date.now(),
|
|
key,
|
|
);
|
|
return result.value;
|
|
}
|
|
|
|
return undefined;
|
|
}
|
|
|
|
async put(key: string, value: string) {
|
|
const result = await this.db.get(
|
|
"SELECT key FROM cache WHERE key = ?",
|
|
key,
|
|
);
|
|
|
|
if (result) {
|
|
await this.db.run(
|
|
"UPDATE cache SET value = ?, timestamp = ? WHERE key = ?",
|
|
value,
|
|
Date.now(),
|
|
key,
|
|
);
|
|
} else {
|
|
const count = await this.db.get("SELECT COUNT(*) as count FROM cache");
|
|
|
|
if (count.count >= AutocompleteLruCache.capacity) {
|
|
await this.db.run(
|
|
"DELETE FROM cache WHERE key = (SELECT key FROM cache ORDER BY timestamp ASC LIMIT 1)",
|
|
);
|
|
}
|
|
|
|
await this.db.run(
|
|
"INSERT INTO cache (key, value, timestamp) VALUES (?, ?, ?)",
|
|
key,
|
|
value,
|
|
Date.now(),
|
|
);
|
|
}
|
|
}
|
|
}
|
|
|
|
export default AutocompleteLruCache;
|