amwps I don't have to worry about any external changes, now every search will loop to get all the files in the directory, and update and write them to sqlite, so every time the files are up-to-date, I tried 20,000 files and completed it quickly.
But then what's the point of storing the result in a database? If every search has to loop through files and directories. It's probably OK to search in real-time, but it could be slow if there are a lot of files and/or slow server and/or many visitors using search at the same time.
amwps It's not a good idea to re-fetch every time,
I will try to refetch the list of files only if the directory has been updated.
Yes. How I would do this, I think there are a few options:
- Create a "publish" function that indexes current file system to database/JSON. This function can be controlled by admin. It's very efficient, but it's not entirely updated until the admin chooses to "publish".
- Create and store a "hash" ID based on the "modified date"
mtime
of all folders. On search, loop all dirs and compare the hash ... If it remains the same, existing database/JSON results can be used. If it has changed, the data needs to be re-indexed because something changed in the file system. This also requires some processing, but simply looping dirs and getting mtime
would be very fast.
- Update the database/JSON on file manager actions (triggered from
index.php
). This would require that all file management is done through the Files gallery ... Or you would need to have a method to index manually if the file system changes from outside Files Gallery.
- Or simply always use real-time search without database/JSON. This should work pretty well in most cases, if the server is fast and there are not a crazy amount of files. It gets tricky if there are many visitors and/or there are a huge amount of files and folders. This is the easy solution.
amwps The popup shows the returned image, and I also need to do CSS layout, or I will organize the search return into json, return it to the filesapp page, and display the search results directly.
Yes. Good job! Of course, the ultimate way to deal with this, would be to display the results directly in Files Gallery, using the standard layouts.