From 7d7902ec9d925c52687c457046bf5949eb82c006 Mon Sep 17 00:00:00 2001 From: Simon Cambier Date: Sun, 13 Oct 2024 18:44:22 +0200 Subject: [PATCH] Warn when too many errors in a short time --- src/repositories/documents-repository.ts | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/src/repositories/documents-repository.ts b/src/repositories/documents-repository.ts index bed489d..ba702de 100644 --- a/src/repositories/documents-repository.ts +++ b/src/repositories/documents-repository.ts @@ -1,4 +1,4 @@ -import { normalizePath, TFile } from 'obsidian' +import { normalizePath, Notice, TFile } from 'obsidian' import type { IndexedDocument } from '../globals' import { extractHeadingsFromCache, @@ -18,14 +18,21 @@ import type OmnisearchPlugin from '../main' import { getNonExistingNotes } from '../tools/notes' export class DocumentsRepository { - /** * The "live cache", containing all indexed vault files * in the form of IndexedDocuments */ private documents: Map = new Map() + private errorsCount = 0 + private errorsWarned = false - constructor(private plugin: OmnisearchPlugin) {} + constructor(private plugin: OmnisearchPlugin) { + setInterval(() => { + if (this.errorsCount > 0) { + --this.errorsCount + } + }, 1000) + } /** * Set or update the live cache with the content of the given file. @@ -46,7 +53,7 @@ export class DocumentsRepository { console.warn(`Omnisearch: Error while adding "${path}" to live cache`, e) // Shouldn't be needed, but... this.removeDocument(path) - // TODO: increment errors counter + this.countError() } } @@ -233,4 +240,13 @@ export class DocumentsRepository { : '', } } + + private countError(): void { + if (++this.errorsCount > 5 && !this.errorsWarned) { + this.errorsWarned = true + new Notice( + 'Omnisearch ⚠️ There might be an issue with your cache. You should clean it in Omnisearch settings and restart Obsidian.' + ) + } + } }