feat(picker.frecency): cleanup old entries from sqlite3 database

This commit is contained in:
Folke Lemaitre 2025-01-18 11:35:23 +01:00
parent bd2da45c38
commit 320a4a62a1
No known key found for this signature in database
GPG key ID: 41F8B1FBACAE2040
3 changed files with 92 additions and 37 deletions

View file

@ -9,7 +9,7 @@ local BONUS_CWD = 10
---@param opts snacks.picker.smart.Config
---@type snacks.picker.finder
function M.smart(opts, filter)
local freceny = require("snacks.picker.core.frecency").new()
local frecency = require("snacks.picker.core.frecency").new()
local done = {} ---@type table<string, boolean>
local cwd = vim.fs.normalize(opts.cwd or (vim.uv or vim.loop).cwd() or ".")
local finder = Snacks.picker.config.finder(opts.finders or { "files", "buffers", "recent" })
@ -19,7 +19,7 @@ function M.smart(opts, filter)
return false
end
done[path] = true
local score = (1 - 1 / (1 + freceny:get(item))) * BONUS_FRECENCY
local score = (1 - 1 / (1 + frecency:get(item))) * BONUS_FRECENCY
item.frecency = score
if path:find(cwd, 1, true) then
score = score + BONUS_CWD