Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save daleharvey/d50a87606d3610e0ebbac5c1a8abff9e to your computer and use it in GitHub Desktop.
Save daleharvey/d50a87606d3610e0ebbac5c1a8abff9e to your computer and use it in GitHub Desktop.
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