Global search: Indexer watches for change#406
Conversation
b7b2c47 to
5516a6e
Compare
There was a problem hiding this comment.
Pull Request Overview
This PR implements real-time indexing for the global search plugin by watching for changes in the current canvas root node. The goal is to provide automatic index updates while the plugin is open, improving the user experience by keeping search results current without manual intervention.
- Adds canvas root node change detection and automatic re-indexing
- Implements a minimum duration hook for improved spinner UX
- Enhances the database with better identification and incremental update capabilities
Reviewed Changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| plugins/global-search/src/utils/useMinimumDuration.ts | New React hook to ensure boolean values stay true for minimum duration |
| plugins/global-search/src/utils/useMinimumDuration.test.ts | Comprehensive test coverage for the minimum duration hook |
| plugins/global-search/src/utils/indexer/indexer.ts | Core indexer logic enhanced with canvas root watching and parallel processing |
| plugins/global-search/src/utils/indexer/IndexerProvider.tsx | Provider updated to handle canvas root change events and accept project name |
| plugins/global-search/src/utils/db.ts | Database schema updated with compound index for efficient incremental updates |
| plugins/global-search/src/components/SearchScene.tsx | UI updated to use minimum duration hook for better spinner behavior |
| plugins/global-search/src/App.tsx | App component updated to pass project name to IndexerProvider |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| if (this.abortRequested) break | ||
| await this.db.upsertEntries(batch) | ||
| } | ||
| this.canvasSubscription ??= framer.subscribeToCanvasRoot(rootNode => { |
There was a problem hiding this comment.
The canvas subscription is only created once using the nullish coalescing assignment operator (??=). If the indexer is restarted multiple times, this could lead to multiple subscriptions being active simultaneously, causing duplicate event handling. The subscription should be properly cleaned up before creating a new one.
| this.canvasSubscription ??= framer.subscribeToCanvasRoot(rootNode => { | |
| // Always clean up any existing canvas subscription before creating a new one | |
| if (this.canvasSubscription) { | |
| this.canvasSubscription(); | |
| this.canvasSubscription = null; | |
| } | |
| this.canvasSubscription = framer.subscribeToCanvasRoot(rootNode => { |
There was a problem hiding this comment.
with the nullish coalescing assignment (what a word to type) there should only be ever one around, when it starts again, the active one is good to be re-used.
… the "other" indexer
5516a6e to
17dd2f9
Compare
niekert
left a comment
There was a problem hiding this comment.
Nice work 👏
LGTM besides some non-blocking nice to have nits
ef94ed4 to
02a8e04
Compare
Description
Watch for changes in the current root node and index them. That will allow for real time index updates while the plugin is open.
Testing