fix: explicit batch instead of blindly on add data

Co-authored-by: Yohan Boniface <yohanboniface@free.fr>
This commit is contained in:
David Larlet 2025-04-04 11:45:26 -04:00
parent d6f591b365
commit b342480f3b
No known key found for this signature in database
GPG key ID: 3E2953A359E7E7BD

View file

@ -327,7 +327,7 @@ export class DataLayer {
this.clear() this.clear()
return this._umap.formatter return this._umap.formatter
.parse(raw, this.options.remoteData.format) .parse(raw, this.options.remoteData.format)
.then((geojson) => this.fromGeoJSON(geojson)) .then((geojson) => this.fromGeoJSON(geojson, false))
.catch((error) => { .catch((error) => {
console.debug(error) console.debug(error)
Alert.error( Alert.error(
@ -460,10 +460,7 @@ export class DataLayer {
try { try {
// Do not fail if remote data is somehow invalid, // Do not fail if remote data is somehow invalid,
// otherwise the layer becomes uneditable. // otherwise the layer becomes uneditable.
this.sync.startBatch() return this.makeFeatures(geojson, sync)
const features = this.makeFeatures(geojson, sync)
this.sync.commitBatch()
return features
} catch (err) { } catch (err) {
console.debug('Error with DataLayer', this.id) console.debug('Error with DataLayer', this.id)
console.error(err) console.error(err)
@ -529,7 +526,11 @@ export class DataLayer {
async importRaw(raw, format) { async importRaw(raw, format) {
return this._umap.formatter return this._umap.formatter
.parse(raw, format) .parse(raw, format)
.then((geojson) => this.addData(geojson)) .then((geojson) => {
this.sync.startBatch()
this.addData(geojson)
this.sync.commitBatch()
})
.catch((error) => { .catch((error) => {
console.debug(error) console.debug(error)
Alert.error(translate('Import failed: invalid data')) Alert.error(translate('Import failed: invalid data'))
@ -926,8 +927,13 @@ export class DataLayer {
this.sync.update('options', this.options, oldOptions) this.sync.update('options', this.options, oldOptions)
} }
this.empty() this.empty()
if (this.isRemoteLayer()) this.fetchRemoteData() if (this.isRemoteLayer()) {
else this.addData(geojson) this.fetchRemoteData()
} else {
this.sync.startBatch()
this.addData(geojson)
this.sync.commitBatch()
}
} }
}) })
} }