The entry to store; its timestamp is the primary key.
Resolves once the write (and any eviction) completes.
await addSearchHistoryEntry({ query: "acetone", timestamp: Date.now(), resultCount: 12 });
export async function addSearchHistoryEntry(entry: SearchHistoryEntry): Promise<void> {
try {
const db = await getDB();
const tx = db.transaction(IDB_STORE.SEARCH_HISTORY, 'readwrite');
const store = tx.objectStore(IDB_STORE.SEARCH_HISTORY);
await store.put(entry);
// Enforce max entries — delete oldest if over limit
const count = await store.count();
if (count > MAX_HISTORY_ENTRIES) {
const excess = count - MAX_HISTORY_ENTRIES;
let cursor = await store.openCursor();
let deleted = 0;
while (cursor && deleted < excess) {
await cursor.delete();
deleted++;
cursor = await cursor.continue();
}
}
await tx.done;
} catch (error) {
logger.error('Failed to add search history entry to IndexedDB', { error });
}
}
Appends a search-history entry, evicting the oldest rows once the store exceeds
maxHistoryEntriesfrom config.json.