Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add missing cache ttl #435

Merged
merged 1 commit into from
Oct 6, 2024
Merged
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
7 changes: 6 additions & 1 deletion web/src/workers/language/language.worker.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type * as monaco from 'monaco-editor'
import * as Comlink from 'comlink'
import { addDays } from 'date-fns'
import { db, keyValue } from '~/services/storage'
import type { GoIndexFile, HoverQuery, LiteralQuery, PackageSymbolQuery, SuggestionQuery } from './types'
import {
Expand All @@ -15,6 +16,10 @@ import type { SymbolIndexItem } from '~/services/storage/types'

const completionVersionKey = 'completionItems.version'

const TTL_DAYS = 7

const getExpireTime = () => addDays(new Date(), TTL_DAYS)

const isPackageQuery = (q: SuggestionQuery): q is PackageSymbolQuery => 'packageName' in q

export class WorkerHandler {
Expand Down Expand Up @@ -190,7 +195,7 @@ export class WorkerHandler {
this.db.symbolIndex.clear(),
this.db.packageIndex.bulkAdd(packages),
this.db.symbolIndex.bulkAdd(symbols),
this.keyValue.setItem(completionVersionKey, data.go),
this.keyValue.setItem(completionVersionKey, data.go, getExpireTime()),
])

this.cachePopulated = true
Expand Down