mirror of
https://github.com/kristoferssolo/telescope-frecency.nvim.git
synced 2025-10-21 20:10:38 +00:00
Detect entries when it has added new ones (#87)
This commit is contained in:
parent
10771fdb7b
commit
62cbd4e7f5
@ -199,7 +199,7 @@ local frecency = function(opts)
|
||||
state.active_filter_tag = filter
|
||||
end
|
||||
|
||||
if vim.tbl_isempty(state.results) or filter_updated then
|
||||
if vim.tbl_isempty(state.results) or db_client.has_updated_results() or filter_updated then
|
||||
state.results = db_client.get_file_scores(state.show_unindexed, ws_dir)
|
||||
end
|
||||
return filter_updated
|
||||
|
||||
@ -182,6 +182,8 @@ local function filter_workspace(workspace_path, show_unindexed)
|
||||
return res
|
||||
end
|
||||
|
||||
local updated = false
|
||||
|
||||
local function get_file_scores(show_unindexed, workspace_path)
|
||||
if not sql_wrapper then return {} end
|
||||
|
||||
@ -205,6 +207,8 @@ local function get_file_scores(show_unindexed, workspace_path)
|
||||
-- sort the table
|
||||
table.sort(scores, function(a, b) return a.score > b.score end)
|
||||
|
||||
updated = false
|
||||
|
||||
return scores
|
||||
end
|
||||
|
||||
@ -218,13 +222,18 @@ local function autocmd_handler(filepath)
|
||||
if file_is_ignored(filepath) then return end
|
||||
|
||||
vim.b.telescope_frecency_registered = 1
|
||||
sql_wrapper:update(filepath)
|
||||
updated = sql_wrapper:update(filepath)
|
||||
end
|
||||
end
|
||||
|
||||
local function has_updated_results()
|
||||
return updated
|
||||
end
|
||||
|
||||
return {
|
||||
init = init,
|
||||
get_file_scores = get_file_scores,
|
||||
autocmd_handler = autocmd_handler,
|
||||
validate = validate_db,
|
||||
has_updated_results = has_updated_results,
|
||||
}
|
||||
|
||||
@ -154,9 +154,11 @@ function M:update(filepath)
|
||||
-- create entry if it doesn't exist
|
||||
local file_id
|
||||
file_id = row_id(self:do_transaction(queries.file_get_entries, {where = {path = filepath}}))
|
||||
local has_added_entry
|
||||
if not file_id then
|
||||
self:do_transaction(queries.file_add_entry, {path = filepath, count = 1})
|
||||
file_id = row_id(self:do_transaction(queries.file_get_entries, {where = {path = filepath}}))
|
||||
has_added_entry = true
|
||||
else
|
||||
-- ..or update existing entry
|
||||
self:do_transaction(queries.file_update_counter, {path = filepath})
|
||||
@ -171,6 +173,8 @@ function M:update(filepath)
|
||||
if trim_at then
|
||||
self:do_transaction(queries.timestamp_delete_before_id, {id = trim_at.id, file_id = file_id})
|
||||
end
|
||||
|
||||
return has_added_entry
|
||||
end
|
||||
|
||||
return M
|
||||
|
||||
Loading…
Reference in New Issue
Block a user