-
Notifications
You must be signed in to change notification settings - Fork 7
tweak: finer-grained events from ClientSyncManager
#6579
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: sync-animation
Are you sure you want to change the base?
Conversation
Summary of ChangesHello @jaskfla, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly refactors the Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
| static #instance: ClientSyncManager | null = null; | ||
|
|
||
| static async getInstance(models: DatatrakWebModelRegistry): Promise<ClientSyncManager> { | ||
| if (!ClientSyncManager.#instance) { | ||
| const deviceId = await getDeviceId(models); | ||
| ClientSyncManager.#instance = new ClientSyncManager(models, deviceId); | ||
| } | ||
| return ClientSyncManager.#instance; | ||
| } | ||
|
|
||
| private database: DatatrakDatabase; | ||
| #database: DatatrakDatabase; | ||
|
|
||
| private models: DatatrakWebModelRegistry; | ||
| #models: DatatrakWebModelRegistry; | ||
|
|
||
| private deviceId: string; | ||
| #deviceId: string; | ||
|
|
||
| private urgentSyncInterval: NodeJS.Timeout | null = null; | ||
| #urgentSyncInterval: ReturnType<typeof setInterval> | null = null; | ||
|
|
||
| private isInitialSync: boolean = false; | ||
| #isInitialSync: boolean = false; | ||
|
|
||
| private syncInterval: NodeJS.Timeout | null = null; | ||
| #syncInterval: ReturnType<typeof setInterval> | null = null; | ||
|
|
||
| progressMaxByStage = STAGE_MAX_PROGRESS_INCREMENTAL; | ||
| #progressMaxByStage: typeof STAGE_MAX_PROGRESS_INCREMENTAL | typeof STAGE_MAX_PROGRESS_INITIAL = | ||
| STAGE_MAX_PROGRESS_INCREMENTAL; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No logical changes
| #progress: number | null = null; | ||
|
|
||
| progress: number | null = null; | ||
| #statusMessage: string | null = null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Renamed “progress message” to “status message”. Honestly could just be “message”, but that might be conflated with the message from stream()
Even though all progress updates come with a message update, not all message updates are tied to sync progressing
e.g. “Requesting sync…” is unrelated to the progress of a sync session
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request refactors the ClientSyncManager class to enhance encapsulation and type safety by migrating internal state properties to TypeScript private class fields (#private). It replaces multiple boolean flags (e.g., isSyncing, isRequestingSync) with a single status property, managed by private setters that emit specific, strongly-typed events (SYNC_STATUS_CHANGED, SYNC_STAGE_CHANGED, SYNC_PROGRESS_CHANGED). The event system itself is updated with new event types and a SyncEvents type for improved clarity and type checking. The SyncPage component is also updated to consume these new ClientSyncManager APIs. A review comment highlighted a redundant this.status = SYNC_STATUS.SYNCING; assignment, suggesting its removal for better code clarity as the status is already correctly set earlier or changed to QUEUING based on session ID validity.
| private set status(status: SyncStatus) { | ||
| this.#status = status; | ||
| this.emitter.emit(SYNC_EVENT_ACTIONS.SYNC_STATUS_CHANGED, { status }); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Emit event when we do syncManager.status = 'newStatus'
Ditto syncStage setter
| get isRequestingSync() { | ||
| return this.#status === 'requesting'; | ||
| } | ||
|
|
||
| get isSyncing() { | ||
| return this.#status === 'syncing'; | ||
| } | ||
|
|
||
| get isQueuing() { | ||
| return this.#status === 'queuing'; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This lets us:
- this.isQueuing = false
- this.isSyncing = true
+ this.status = 'syncing'46a3e45 to
c7475b2
Compare
| get emitter() { | ||
| return this.#emitter; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Felt strange that we could, in React-land, just overwrite the emitter. Not sure it was a “real” problem, but this was so trivial to tighten up
| this.emitter.emit(SYNC_EVENT_ACTIONS.SYNC_ERROR, { error: error.message }); | ||
| this.errorMessage = error.message; | ||
| } finally { | ||
| // Reset all the values to default only if sync actually started, otherwise they should still be default values |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Idempotent anyway, so took out the if
Hard to keep the if guard because the try and catch blocks update the status to IDLE | ERROR, so isSyncing will always be false in the finally block
3ae6bbd to
faabf50
Compare
|
|
||
| if (this.#urgentSyncInterval) { | ||
| clearInterval(this.#urgentSyncInterval); | ||
| this.#urgentSyncInterval = null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: Urgent sync retry interval cleared prematurely when queued
The finally block unconditionally clears #urgentSyncInterval, but this breaks the urgent sync retry mechanism. Previously, the if (this.isSyncing) guard in the finally block prevented the interval from being cleared when sync was merely queued (returned early without actually syncing). Now when an urgent sync is queued by the server, the interval is immediately cleared after the first attempt, preventing the scheduled retries that are supposed to poll for queue status changes every 10 seconds.
9530f0a to
ba7a20d
Compare
d4881d6 to
4ebb718
Compare
No description provided.