Elffuss BraidHub

kikocis/continue public

main · 756 BRawPermalink
1import QuickLRU from "quick-lru";
2
3export interface prevEdit {
4 unidiff: string;
5 fileUri: string;
6 workspaceUri: string;
7 timestamp: number;
8}
9const maxPrevEdits = 5;
10
11export const prevEditLruCache = new QuickLRU<string, prevEdit>({
12 maxSize: maxPrevEdits,
13});
14
15export const setPrevEdit = (edit: prevEdit): void => {
16 const uniqueSuffix = Math.random().toString(36).substring(2, 8);
17 const key = `${edit.fileUri}:${edit.timestamp}:${uniqueSuffix}`;
18 prevEditLruCache.set(key, edit);
19};
20
21export const getPrevEditsDescending = (): prevEdit[] => {
22 const edits: prevEdit[] = [];
23 for (const [_, edit] of prevEditLruCache.entriesDescending()) {
24 if (edits.length >= maxPrevEdits) {
25 break;
26 }
27 edits.push(edit);
28 }
29 return edits;
30};