Skip to content

Conversation

@xianxu
Copy link

@xianxu xianxu commented May 4, 2025

When files are deleted, they are stuck in the DB and still show up in telescope. This change fixed that by tracking if a file exists before displaying it, and asynchronously removing all selectable but deleted files from the database later. This might cause performance issues, but on my Apple M4 Max, even running require('telescope').extensions.frecency.frecency({ workspace = "CWD" }) on home directory with 64K recursive files, it seems to run smoothly. Nonetheless, I added a flag to disable this behavior if needed.

@delphinus
Copy link
Member

Nice work! IMO, It may not be done every time, but it should be done once for several times opening frecency. I will think this later again.

But I must point out here.

-- Remove deleted files from database in the background after telescope display is complete
if check_existence and #deleted_files > 0 then
log.debug("Removing " .. #deleted_files .. " deleted files from database")
async.void(function()
self.database:remove_files(deleted_files)
end)()
end

This process will not be executed “after telescope display is complete”. This code means it removes candidates “at the next loop”. If we want to do this precisely after showing candidates, we should do after here.

Can you move this logic after process_complete()?

@xianxu
Copy link
Author

xianxu commented May 6, 2025

But I must point out here.

-- Remove deleted files from database in the background after telescope display is complete
if check_existence and #deleted_files > 0 then
log.debug("Removing " .. #deleted_files .. " deleted files from database")
async.void(function()
self.database:remove_files(deleted_files)
end)()
end

This process will not be executed “after telescope display is complete”. This code means it removes candidates “at the next loop”. If we want to do this precisely after showing candidates, we should do after here.

Can you move this logic after process_complete()?

It's a bit subtle, there are two filters actually, one to decide if adding to UI, here:

if not check_existence or fs.exists(file.path) then

and the one you pointed out was to if remove from db. I do think the following line the check_existence in this context is redundant, as if check_existence is false, #deleted_files has to be 0.

if check_existence and #deleted_files > 0 then

do I need to worry about the nightly failure in Ubuntu latest? I don't have a ubuntu...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants