anything-llm
anything-llm copied to clipboard
#2317 Reduce workspace popup loading time by 98% when there are many files
Pull Request Type
- [ ] ✨ feat
- [x] 🐛 fix
- [ ] ♻️ refactor
- [ ] 💄 style
- [ ] 🔨 chore
- [ ] 📝 docs
Relevant Issues
connect #2317
What is in this change?
Reduces the loading time of the documents popup by fetching pinned documents once per folder.
Results on my local instance with ~14k files:
- loading time
- before: 105 seconds
- after: 2 seconds
- number of queries for pinned documents:
- before: ~14k
- after: 8
Before
[0.05ms] Checked/created documentsPath
[1.28ms] Checked DocumentSyncQueue.enabled()
[2.29ms] Read subfolder: custom-documents
[122.83ms] Read subfolder: folder1
[205.92ms] Read subfolder: folder2
[301.90ms] Read subfolder: folder3
[336.27ms] Read subfolder: folder4
[35961.37ms] Read subfolder: folder5
[49814.86ms] Read subfolder: folder6
[51723.69ms] Read subfolder: folder7
[105922.62ms] Finished processing all folders and files
Function call timings summary:
readFile: 1939.09ms
parseJSON: 694.86ms
getPinnedWorkspaces: 100892.30ms
getWatchedWorkspaces: 6.67ms
checkCachedVector: 1971.95ms
After
[0.05ms] Checked/created documentsPath
[11.17ms] Checked DocumentSyncQueue.enabled()
[12.08ms] Read subfolder: custom-documents
[54.88ms] Read subfolder: folder1
[65.54ms] Read subfolder: folder2
[74.09ms] Read subfolder: folder3
[90.14ms] Read subfolder: folder4
[648.97ms] Read subfolder: folder5
[781.37ms] Read subfolder: folder6
[817.45ms] Read subfolder: folder7
[1926.20ms] Finished processing all folders and files
Function call timings summary:
readFile: 734.33ms
parseJSON: 398.08ms
getPinnedWorkspaces: 328.55ms
getWatchedWorkspaces: 1.58ms
checkCachedVector: 288.89ms
Additional Information
An additional optional parameter select
has been added to Document.where
.
Developer Validations
- [x] I ran
yarn lint
from the root of the repo & committed changes - [x] Relevant documentation has been updated
- [x] I have tested my code functionality
- [x] Docker build succeeds locally