Detect entries when it has added new ones (#87)

This commit is contained in:
JINNOUCHI Yasushi 2022-12-28 20:25:07 +09:00 committed by GitHub
parent 10771fdb7b
commit 62cbd4e7f5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 2 deletions

View File

@ -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

View File

@ -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,
}

View File

@ -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