Cleaning old cache files

This commit is contained in:
Simon Cambier
2022-10-12 21:03:23 +02:00
parent 64e47f13f3
commit 6c736fc90f
3 changed files with 42 additions and 21 deletions

View File

@@ -17,6 +17,9 @@ export const notesCacheFilePath = `${app.vault.configDir}/plugins/omnisearch/not
export const pdfCacheFilePath = `${app.vault.configDir}/plugins/omnisearch/pdfCache.data`
export const historyFilePath = `${app.vault.configDir}/plugins/omnisearch/historyCache.json`
export const oldSearchIndexFilePath = `${app.vault.configDir}/plugins/omnisearch/searchIndex.json`
export const oldNnotesCacheFilePath = `${app.vault.configDir}/plugins/omnisearch/notesCache.json`
export const EventNames = {
ToggleExcerpts: 'toggle-excerpts',
} as const

View File

@@ -1,12 +1,17 @@
import { Plugin, TFile } from 'obsidian'
import { Notice, Plugin, TFile } from 'obsidian'
import * as Search from './search'
import { OmnisearchInFileModal, OmnisearchVaultModal } from './modals'
import { loadSettings, settings, SettingsTab, showExcerpt } from './settings'
import { eventBus, EventNames } from './globals'
import {
eventBus,
EventNames,
oldNnotesCacheFilePath,
oldSearchIndexFilePath,
} from './globals'
import { registerAPI } from '@vanakat/plugin-api'
import api from './api'
import { loadSearchHistory } from './search-history'
import { isFilePlaintext, showWelcomeNotice } from './utils'
import { isFilePlaintext } from './utils'
import * as NotesIndex from './notes-index'
import { cacheManager } from './cache-manager'
import { pdfManager } from './pdf-manager'
@@ -21,7 +26,7 @@ function _registerAPI(plugin: OmnisearchPlugin): void {
export default class OmnisearchPlugin extends Plugin {
async onload(): Promise<void> {
await cleanOldCacheFiles()
await loadSettings(this)
await loadSearchHistory()
await cacheManager.loadNotesCache()
@@ -100,3 +105,33 @@ export default class OmnisearchPlugin extends Plugin {
})
}
}
async function cleanOldCacheFiles() {
if (await app.vault.adapter.exists(oldSearchIndexFilePath)) {
try {
await app.vault.adapter.remove(oldSearchIndexFilePath)
} catch (e) {}
}
if (await app.vault.adapter.exists(oldNnotesCacheFilePath)) {
try {
await app.vault.adapter.remove(oldNnotesCacheFilePath)
} catch (e) {}
}
}
function showWelcomeNotice(plugin: Plugin) {
return
const code = '1.6.0'
if (settings.welcomeMessage !== code) {
const welcome = new DocumentFragment()
welcome.createSpan({}, span => {
span.innerHTML = `<strong>Omnisearch has been updated</strong>
New beta feature: PDF search 🔎📄
<small>Toggle "<i>BETA - Index PDFs</i>" in Omnisearch settings page.</small>`
})
new Notice(welcome, 30000)
}
settings.welcomeMessage = code
plugin.saveData(settings)
}

View File

@@ -192,23 +192,6 @@ export function getExtension(path: string): string {
return split[split.length - 1]
}
export function showWelcomeNotice(plugin: Plugin) {
return
const code = '1.6.0'
if (settings.welcomeMessage !== code) {
const welcome = new DocumentFragment()
welcome.createSpan({}, span => {
span.innerHTML = `<strong>Omnisearch has been updated</strong>
New beta feature: PDF search 🔎📄
<small>Toggle "<i>BETA - Index PDFs</i>" in Omnisearch settings page.</small>`
})
new Notice(welcome, 30000)
}
settings.welcomeMessage = code
plugin.saveData(settings)
}
export function md5(data: BinaryLike): string {
return createHash('md5').update(data).digest('hex')
}