Optimize synchronization with two-step metadata check and new interval options#65
Open
adiagarwalrock wants to merge 3 commits into
Open
Optimize synchronization with two-step metadata check and new interval options#65adiagarwalrock wants to merge 3 commits into
adiagarwalrock wants to merge 3 commits into
Conversation
…p metadata check before fetching full data, and add new sync interval options.
There was a problem hiding this comment.
Pull request overview
This PR optimizes client-side live sync/polling for diagrams and notes by adding a lightweight “metadata first” check (updated timestamps) before fetching full payloads, and expands configurable sync intervals. It also introduces API support for metadata-only selection and adds Docker Compose deployment configs.
Changes:
- Update
useLiveSync/useListSyncto do a metadata check (select=updatedAt/select=id,updatedAt) before fetching full data. - Add metadata-only support in diagrams/notes list + item endpoints and new helpers to fetch only
updatedAt. - Increase the default live sync interval and add longer interval choices in Settings; add Docker Compose configurations.
Reviewed changes
Copilot reviewed 11 out of 13 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
| src/lib/useLiveSync.ts | Two-step polling: check updatedAt first, fetch full resource only on change; default interval increased. |
| src/lib/useListSync.ts | Two-step list polling: fetch id,updatedAt first, fetch full list only if changed. |
| src/lib/store.ts | Updates default settings (liveSyncInterval now 30s). |
| src/lib/notes-data.ts | Adds metadataOnly mode for notes paging + getNoteUpdatedAt. |
| src/lib/data.ts | Adds metadataOnly mode for diagrams paging + getDiagramUpdatedAt. |
| src/components/DashboardHeader.tsx | Minor Tailwind class reordering. |
| src/app/settings/page.tsx | Adds 1-minute and 5-minute interval options. |
| src/app/api/notes/route.ts | Supports select=id,updatedAt for metadata-only list responses when bypassing cache. |
| src/app/api/notes/[id]/route.ts | Supports select=updatedAt for fresh metadata-only fetch. |
| src/app/api/diagrams/route.ts | Supports select=id,updatedAt for metadata-only list responses when bypassing cache. |
| src/app/api/diagrams/[id]/route.ts | Supports select=updatedAt for fresh metadata-only fetch. |
| docker/docker-compose.yml | Adds full-stack compose (app + Redis). |
| docker/docker-compose.simple.yml | Adds simplified compose (app only). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
… into fix/live-sync-payload
- Refactor `getDiagramPage` and `getNotePage` functions to support metadata-only retrieval. - Introduce `DiagramMetadataPage` and `NoteMetadataPage` interfaces for structured metadata responses. - Implement utility functions for normalization of limits and offsets. - Add sorting capabilities for diagrams and notes based on various criteria. - Improve database URL resolution with writable path checks for SQLite. - Update Zustand store to ensure proper merging of persisted settings. - Enhance type definitions for better clarity and maintainability.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request introduces several optimizations and improvements to the live sync and polling mechanisms for diagrams and notes, as well as some UI and configuration enhancements. The main focus is on reducing unnecessary data transfer during polling by first fetching only metadata (such as
idandupdatedAt) to check for changes, and only fetching full content if changes are detected. Additionally, the default live sync interval is increased, and users can now select longer sync intervals in the settings.Live Sync and Polling Optimizations:
useListSyncanduseLiveSynchooks now perform an initial lightweight metadata fetch (usingselect=id,updatedAtorselect=updatedAt) to detect changes, and only fetch full data if a change is detected. This reduces bandwidth and improves efficiency. [1] [2] [3]/api/diagramsand/api/notesendpoints support aselectquery parameter, allowing clients to request only specific fields (e.g.,id,updatedAt), and the corresponding data access functions (getDiagramPage,getNotePage) support ametadataOnlyflag to return minimal objects for sync checks. [1] [2] [3] [4] [5] [6]getDiagramUpdatedAtandgetNoteUpdatedAtare added to fetch only theupdatedAtfield for individual diagrams and notes. The GET handlers for/api/diagrams/[id]and/api/notes/[id]use these whenselect=updatedAtis requested. (src/app/api/diagrams/[id]/route.tsL12-R12, src/app/api/diagrams/[id]/route.tsR25-R35, [1] src/app/api/notes/[id]/route.tsL14-R14, src/app/api/notes/[id]/route.tsR40-R50, [2]Live Sync Interval and Settings:
UI and Minor Improvements:
DashboardHeadercomponent for improved class order and readability.These changes collectively improve the scalability and efficiency of live sync, especially for users with large lists of diagrams or notes.