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
This commit is contained in:
1 file changed
+7
-5
@@ -15,15 +15,15 @@ export default class FreewritingCleanupPlugin extends Plugin {
|
|||||||
cleanupCommand: CleanupCommand;
|
cleanupCommand: CleanupCommand;
|
||||||
|
|
||||||
async onload() {
|
async onload() {
|
||||||
await this.loadSettings();
|
// Load settings and reuse the data to avoid double loadData() call
|
||||||
|
const data = await this.loadSettings();
|
||||||
|
|
||||||
// Initialize services
|
// Initialize services
|
||||||
this.cleanupService = new CleanupService(this.settings.apiKey);
|
this.cleanupService = new CleanupService(this.settings.apiKey);
|
||||||
this.modelService = new ModelService(this.cleanupService.anthropicClient);
|
this.modelService = new ModelService(this.cleanupService.anthropicClient);
|
||||||
this.cleanupCommand = new CleanupCommand(this.cleanupService);
|
this.cleanupCommand = new CleanupCommand(this.cleanupService);
|
||||||
|
|
||||||
// Load model cache
|
// Load model cache from already-loaded data
|
||||||
const data = await this.loadData() as FreewritingCleanupData | null;
|
|
||||||
if (data?.modelCache) {
|
if (data?.modelCache) {
|
||||||
this.modelService.loadCache(data.modelCache);
|
this.modelService.loadCache(data.modelCache);
|
||||||
}
|
}
|
||||||
@@ -41,8 +41,10 @@ export default class FreewritingCleanupPlugin extends Plugin {
|
|||||||
|
|
||||||
// MARK: - Settings Management
|
// MARK: - Settings Management
|
||||||
|
|
||||||
async loadSettings() {
|
async loadSettings(): Promise<FreewritingCleanupData | null> {
|
||||||
this.settings = Object.assign({}, DEFAULT_SETTINGS, await this.loadData());
|
const data = await this.loadData() as FreewritingCleanupData | null;
|
||||||
|
this.settings = Object.assign({}, DEFAULT_SETTINGS, data);
|
||||||
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
async saveSettings() {
|
async saveSettings() {
|
||||||
|
|||||||
Reference in new issue
Block a user