diff --git a/src/utils/FieldSuggestionCache.ts b/src/utils/FieldSuggestionCache.ts index 9f9176e0..d44e2a88 100644 --- a/src/utils/FieldSuggestionCache.ts +++ b/src/utils/FieldSuggestionCache.ts @@ -11,7 +11,6 @@ export class FieldSuggestionCache { private cache: Map = new Map(); private readonly TTL = 5 * 60 * 1000; // 5 minutes in milliseconds private readonly MAX_CACHE_ENTRIES = 100; // Maximum number of cache entries - private readonly MAX_VALUES_PER_ENTRY = 1000; // Maximum values per field private cleanupInterval: number | null = null; private revision = 0; @@ -90,12 +89,6 @@ export class FieldSuggestionCache { set(fieldName: string, values: Set, cacheKey?: string): void { const key = this.makeKey(fieldName, cacheKey); - const limitedValues = new Set(); - for (const value of values) { - if (limitedValues.size >= this.MAX_VALUES_PER_ENTRY) break; - limitedValues.add(value); - } - // Check if we need to evict old entries if (this.cache.size >= this.MAX_CACHE_ENTRIES && !this.cache.has(key)) { this.evictOldestEntries(1); @@ -103,7 +96,7 @@ export class FieldSuggestionCache { this.cache.set(key, { fieldName, - values: limitedValues, + values: new Set(values), timestamp: Date.now(), }); } diff --git a/src/utils/FieldValueCollector.issue2108.test.ts b/src/utils/FieldValueCollector.issue2108.test.ts new file mode 100644 index 00000000..b40657bd --- /dev/null +++ b/src/utils/FieldValueCollector.issue2108.test.ts @@ -0,0 +1,23 @@ +import { beforeEach, describe, expect, it } from "vitest"; +import { App } from "obsidian"; +import { FieldSuggestionCache } from "./FieldSuggestionCache"; +import { collectFieldValuesProcessed } from "./FieldValueCollector"; + +describe("Issue #2108 - FIELD values past the first 1,000", () => { + beforeEach(() => { + FieldSuggestionCache.getInstance().clear(); + }); + + it("offers every value again when the second prompt reads the cache", async () => { + const app = new App(); + const files = Array.from({ length: 1500 }, (_, i) => ({ path: `Books/${i}.md`, author: `Author ${i}` })); + app.vault.getMarkdownFiles = () => files as any[]; + app.metadataCache.getFileCache = (file: any) => ({ frontmatter: { author: file.author } }) as any; + + const first = await collectFieldValuesProcessed(app, "author", {}); + const second = await collectFieldValuesProcessed(app, "author", {}); + + expect(first).toHaveLength(1500); + expect(second).toEqual(first); + }); +});