Optimisation for File Searches
conaticus opened this issue · 4 comments
Currently the entire disk is searched before results are shown in the UI. It would be better if they are sent to the UI as soon as they are found for maximum efficiency. With this, we should also take advantage of hashmaps and try and index the precise filename (incl extension filter if needed) and then doing the whole disk search.
I wonder if it is possible for a Rust command in Tauri to get the response right into the UI once it has been found.
It has to be some sort of event emitted to the UI for it to handle it and update the list of files that are shown in it. I have been trying to solve this problem for @conaticus's explorer, but am completely stuck at the same problem.
@kul-sudo should be solvable with WebSockets.
There is propably a smarter way, but the client part would need to generate a random UUID or just increment an atomic int. With that ID it registers a handler in some WebSocket handling service on the client.
The rust command in the tauri server part would get the ID, handle the request and stream json data with the given ID to the WebSocket while the rust command is being processed.
The WebSocket service on the client side receives the data packages, selects the handler based on the id and calls the handler with the data.
There just needs to be an end-of-data message so the handler on the client side can be released so we do not leak memory.
I would suggest always passing an array. For example you would want to stream all newly found files every x milliseconds, rather than every item independently and then rerendering the UI for every Item causing lag if search is fast.
https://github.com/tauri-apps/tauri-plugin-websocket
I did not use or take a look at this plugin yet, but I did something with tauri and WebSockets using a (bad) custom setup.
https://github.com/kul-sudo/explo
I have found a very simple solution you can see in the main.rs
back-end and the index.tsx
front-end. Please, don't look at the other features, because many of them are still pretty defective, only searching isn't.
https://github.com/kul-sudo/explo
I have found a very simple solution you can see in the
main.rs
back-end and theindex.tsx
front-end. Please, don't look at the other features, because many of them are still pretty defective, only searching isn't.
Would like to add that I have fully completed this app, so you can take something from it for your explorer.