Created
June 9, 2020 08:46
-
-
Save daleharvey/d50a87606d3610e0ebbac5c1a8abff9e to your computer and use it in GitHub Desktop.
This file contains 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
async _ensureRegionFilesDownloaded() { | |
log.info("_ensureRegionFilesDownloaded"); | |
this._remoteSettings.on( | |
"sync", | |
async ({ data: { created, updated, deleted } }) => { | |
log.info("_ensureRegionFilesDownloaded data synced"); | |
const toDelete = deleted.filter(d => d.attachment); | |
const toDownload = created | |
.concat(updated.map(u => u.new)) | |
.filter(d => d.attachment); | |
// Remove local files of deleted records | |
await Promise.all( | |
toDelete.map(entry => this._remoteSettings.attachments.delete(entry)) | |
); | |
// Download attachments | |
log.info("_ensureRegionFilesDownloaded downloading attachments"); | |
await Promise.all( | |
toDownload.map(entry => | |
this._remoteSettings.attachments.download(entry, { | |
retries: 2, | |
useCache: true, | |
}) | |
) | |
); | |
this._regionFilesReady = true; | |
log.info("_ensureRegionFilesDownloaded completed"); | |
} | |
); | |
await this._remoteSettings.sync(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment