Skip to content

Commit 7c4da41

Browse files
authored
Improve docs of sync timing variables in the attachments helper (#894)
1 parent e9ec0f1 commit 7c4da41

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

packages/common/src/attachments/AttachmentQueue.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,16 @@ export class AttachmentQueue {
5151
/** Logger instance for diagnostic information */
5252
readonly logger: ILogger;
5353

54-
/** Interval in milliseconds between periodic sync operations. Default: 30000 (30 seconds) */
54+
/** Interval in milliseconds between periodic sync operations. Acts as a polling timer to retry
55+
* failed uploads/downloads, especially after the app goes offline. Default: 30000 (30 seconds) */
5556
readonly syncIntervalMs: number = 30 * 1000;
5657

57-
/** Duration in milliseconds to throttle sync operations */
58+
/** Throttle duration in milliseconds for the reactive watch query on the attachments table.
59+
* When attachment records change, a watch query detects the change and triggers a sync.
60+
* This throttle prevents the sync from firing too rapidly when many changes happen in
61+
* quick succession (e.g., bulk inserts). This is distinct from syncIntervalMs — it controls
62+
* how quickly the queue reacts to changes, while syncIntervalMs controls how often it polls
63+
* for retries. Default: 30 (from DEFAULT_WATCH_THROTTLE_MS) */
5864
readonly syncThrottleDuration: number;
5965

6066
/** Whether to automatically download remote attachments. Default: true */
@@ -86,8 +92,8 @@ export class AttachmentQueue {
8692
* @param options.watchAttachments - Callback for monitoring attachment changes in your data model
8793
* @param options.tableName - Name of the table to store attachment records. Default: 'ps_attachment_queue'
8894
* @param options.logger - Logger instance. Defaults to db.logger
89-
* @param options.syncIntervalMs - Interval between automatic syncs in milliseconds. Default: 30000
90-
* @param options.syncThrottleDuration - Throttle duration for sync operations in milliseconds. Default: 1000
95+
* @param options.syncIntervalMs - Periodic polling interval in milliseconds for retrying failed uploads/downloads. Default: 30000
96+
* @param options.syncThrottleDuration - Throttle duration in milliseconds for the reactive watch query that detects attachment changes. Prevents rapid-fire syncs during bulk changes. Default: 30
9197
* @param options.downloadAttachments - Whether to automatically download remote attachments. Default: true
9298
* @param options.archivedCacheLimit - Maximum archived attachments before cleanup. Default: 100
9399
*/

packages/common/src/attachments/README.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -289,8 +289,8 @@ new AttachmentQueue(options: AttachmentQueueOptions)
289289
| `watchAttachments` | `(onUpdate: (attachments: WatchedAttachmentItem[]) => Promise<void>) => void` | Yes | - | Callback to determine which attachments to handle by the queue from your user defined query |
290290
| `tableName` | `string` | No | `'attachments'` | Name of the attachments table |
291291
| `logger` | `ILogger` | No | `db.logger` | Logger instance for diagnostic output |
292-
| `syncIntervalMs` | `number` | No | `30000` | Interval between automatic syncs in milliseconds |
293-
| `syncThrottleDuration` | `number` | No | `30` | Throttle duration for sync operations in milliseconds |
292+
| `syncIntervalMs` | `number` | No | `30000` | Periodic polling interval (in milliseconds) for retrying failed uploads/downloads. A `setInterval` timer that calls `syncStorage()` on this cadence, ensuring operations are retried even if no database changes occur (e.g., after coming back online). |
293+
| `syncThrottleDuration` | `number` | No | `30` | Throttle duration (in milliseconds) for the reactive watch query on the attachments table. When attachment records change (e.g., a new file is queued), a watch query detects the change and triggers a sync. This throttle prevents the sync from firing too rapidly when many changes happen in quick succession (e.g., bulk inserts). This is distinct from `syncIntervalMs` — it controls how quickly the queue *reacts* to changes, while `syncIntervalMs` controls how often it *polls* for retries. |
294294
| `downloadAttachments` | `boolean` | No | `true` | Whether to automatically download remote attachments |
295295
| `archivedCacheLimit` | `number` | No | `100` | Maximum number of archived attachments before cleanup |
296296
| `errorHandler` | `AttachmentErrorHandler` | No | `undefined` | Custom error handler for upload/download/delete operations |
@@ -676,11 +676,13 @@ Adjust sync frequency based on your needs:
676676
```typescript
677677
const queue = new AttachmentQueue({
678678
// ... other options
679-
syncIntervalMs: 60000, // Sync every 60 seconds instead of 30
679+
syncIntervalMs: 60000, // Poll for retries every 60 seconds instead of 30
680+
syncThrottleDuration: 100, // React to attachment changes within 100ms (default: 30ms)
680681
});
681682
```
682683

683-
Set to `0` to disable periodic syncing (manual `syncStorage()` calls only).
684+
- **`syncIntervalMs`** controls the periodic polling timer — how often the queue retries failed operations.
685+
- **`syncThrottleDuration`** controls how quickly the queue reacts to attachment table changes. The default (30ms) is fast enough for most use cases. Increase it if you see performance issues during bulk attachment operations.
684686

685687
### Archive and Cache Management
686688

0 commit comments

Comments
 (0)