|
1 | | -import { AbstractPowerSyncDatabase, ILogger, Transaction } from '@powersync/common'; |
| 1 | +import { AbstractPowerSyncDatabase, DifferentialWatchedQuery, ILogger, Transaction } from '@powersync/common'; |
2 | 2 | import { AttachmentContext } from './AttachmentContext.js'; |
3 | 3 | import { LocalStorageAdapter } from './LocalStorageAdapter.js'; |
4 | 4 | import { RemoteStorageAdapter } from './RemoteStorageAdapter.js'; |
@@ -54,6 +54,8 @@ export class AttachmentQueue { |
54 | 54 | /** Service for managing attachment-related database operations */ |
55 | 55 | attachmentService: AttachmentService; |
56 | 56 |
|
| 57 | + watchActiveAttachments: DifferentialWatchedQuery<AttachmentRecord>; |
| 58 | + |
57 | 59 | /** |
58 | 60 | * Creates a new AttachmentQueue instance. |
59 | 61 | * |
@@ -99,6 +101,7 @@ export class AttachmentQueue { |
99 | 101 | this.tableName = tableName; |
100 | 102 | this.syncingService = new SyncingService(this.context, localStorage, remoteStorage, logger ?? db.logger); |
101 | 103 | this.attachmentService = new AttachmentService(tableName, db); |
| 104 | + this.watchActiveAttachments = this.attachmentService.watchActiveAttachments(); |
102 | 105 | this.syncIntervalMs = syncIntervalMs; |
103 | 106 | this.syncThrottleDuration = syncThrottleDuration; |
104 | 107 | this.downloadAttachments = downloadAttachments; |
@@ -138,7 +141,7 @@ export class AttachmentQueue { |
138 | 141 | }, this.syncIntervalMs); |
139 | 142 |
|
140 | 143 | // Sync storage when there is a change in active attachments |
141 | | - this.attachmentService.watchActiveAttachments().registerListener({ |
| 144 | + this.watchActiveAttachments.registerListener({ |
142 | 145 | onDiff: async () => { |
143 | 146 | await this.syncStorage(); |
144 | 147 | } |
@@ -247,7 +250,7 @@ export class AttachmentQueue { |
247 | 250 | async stopSync(): Promise<void> { |
248 | 251 | clearInterval(this.periodicSyncTimer); |
249 | 252 | this.periodicSyncTimer = undefined; |
250 | | - await this.attachmentService.watchActiveAttachments().close(); |
| 253 | + await this.watchActiveAttachments.close(); |
251 | 254 | } |
252 | 255 |
|
253 | 256 | /** |
|
0 commit comments