You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: packages/common/src/attachments/AttachmentQueue.ts
+10-4Lines changed: 10 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -51,10 +51,16 @@ export class AttachmentQueue {
51
51
/** Logger instance for diagnostic information */
52
52
readonlylogger: ILogger;
53
53
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) */
55
56
readonlysyncIntervalMs: number=30*1000;
56
57
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) */
58
64
readonlysyncThrottleDuration: number;
59
65
60
66
/** Whether to automatically download remote attachments. Default: true */
@@ -86,8 +92,8 @@ export class AttachmentQueue {
86
92
* @param options.watchAttachments - Callback for monitoring attachment changes in your data model
87
93
* @param options.tableName - Name of the table to store attachment records. Default: 'ps_attachment_queue'
88
94
* @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
Copy file name to clipboardExpand all lines: packages/common/src/attachments/README.md
+6-4Lines changed: 6 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -289,8 +289,8 @@ new AttachmentQueue(options: AttachmentQueueOptions)
289
289
|`watchAttachments`|`(onUpdate: (attachments: WatchedAttachmentItem[]) => Promise<void>) => void`| Yes | - | Callback to determine which attachments to handle by the queue from your user defined query |
290
290
|`tableName`|`string`| No |`'attachments'`| Name of the attachments table |
291
291
|`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.|
294
294
|`downloadAttachments`|`boolean`| No |`true`| Whether to automatically download remote attachments |
295
295
|`archivedCacheLimit`|`number`| No |`100`| Maximum number of archived attachments before cleanup |
296
296
|`errorHandler`|`AttachmentErrorHandler`| No |`undefined`| Custom error handler for upload/download/delete operations |
@@ -676,11 +676,13 @@ Adjust sync frequency based on your needs:
676
676
```typescript
677
677
const queue =newAttachmentQueue({
678
678
// ... 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)
680
681
});
681
682
```
682
683
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.
0 commit comments