Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 1 addition & 8 deletions src/utils/FieldSuggestionCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ export class FieldSuggestionCache {
private cache: Map<string, CacheEntry> = 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;

Expand Down Expand Up @@ -90,20 +89,14 @@ export class FieldSuggestionCache {
set(fieldName: string, values: Set<string>, cacheKey?: string): void {
const key = this.makeKey(fieldName, cacheKey);

const limitedValues = new Set<string>();
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);
}

this.cache.set(key, {
fieldName,
values: limitedValues,
values: new Set(values),
Comment thread
macroscopeapp[bot] marked this conversation as resolved.
timestamp: Date.now(),
});
}
Expand Down
23 changes: 23 additions & 0 deletions src/utils/FieldValueCollector.issue2108.test.ts
Original file line number Diff line number Diff line change
@@ -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);
});
});
Loading