From c3d4888c986c8180434345f32eb23c8a1cafe917 Mon Sep 17 00:00:00 2001 From: Alexander Kucera Date: Fri, 24 Oct 2025 10:57:47 +0200 Subject: [PATCH] Optimizes settings and model cache loading Refactors loadSettings method to avoid redundant data loading Reduces duplicate loadData() calls by reusing loaded data Improves efficiency of plugin initialization process --- main.ts | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/main.ts b/main.ts index a0b0bcc..46d41dc 100644 --- a/main.ts +++ b/main.ts @@ -15,15 +15,15 @@ export default class FreewritingCleanupPlugin extends Plugin { cleanupCommand: CleanupCommand; async onload() { - await this.loadSettings(); + // Load settings and reuse the data to avoid double loadData() call + const data = await this.loadSettings(); // Initialize services this.cleanupService = new CleanupService(this.settings.apiKey); this.modelService = new ModelService(this.cleanupService.anthropicClient); this.cleanupCommand = new CleanupCommand(this.cleanupService); - // Load model cache - const data = await this.loadData() as FreewritingCleanupData | null; + // Load model cache from already-loaded data if (data?.modelCache) { this.modelService.loadCache(data.modelCache); } @@ -41,8 +41,10 @@ export default class FreewritingCleanupPlugin extends Plugin { // MARK: - Settings Management - async loadSettings() { - this.settings = Object.assign({}, DEFAULT_SETTINGS, await this.loadData()); + async loadSettings(): Promise { + const data = await this.loadData() as FreewritingCleanupData | null; + this.settings = Object.assign({}, DEFAULT_SETTINGS, data); + return data; } async saveSettings() {