fixup: prevent to reload a datalayer after other peer has saved it

The scenario to reproduce is:
- peer A creates a datalayer
- peer B add a marker on that datalayer
- peer B saves the datalayer

Before this fix, after the save, peer A would get a new _referenceVersion
for this datalayer, and the render method would make a hide/show,
which would refetch the data from the server, duplicating it.
So forcing the _loaded to be true in this situation prevent this.

We may want to rework the "_loaded" pattern, maybe with the server
returning in a datalayer metadata the length of the data it get for
this given datalayer, so the client knows if it is worth getting
data for a layer when itself (the client) does not have any.

Co-authored-by: David Larlet <david@larlet.fr>
This commit is contained in:
Yohan Boniface 2025-02-07 17:54:33 +01:00
parent a172c4abea
commit eca7ad4772
2 changed files with 8 additions and 5 deletions

View file

@ -63,6 +63,7 @@ export class DataLayerUpdater extends BaseUpdater {
update({ key, metadata, value }) {
const datalayer = this.getDataLayerFromID(metadata.id)
if (fieldInSchema(key)) {
datalayer._loaded = true
this.updateObjectValue(datalayer, key, value)
} else {
console.debug(
@ -92,7 +93,7 @@ export class FeatureUpdater extends BaseUpdater {
upsert({ metadata, value }) {
const { id, layerId } = metadata
const datalayer = this.getDataLayerFromID(layerId)
const feature = this.getFeatureFromMetadata(metadata, value)
const feature = this.getFeatureFromMetadata(metadata)
if (feature) {
feature.geometry = value.geometry
@ -109,7 +110,7 @@ export class FeatureUpdater extends BaseUpdater {
return
}
if (key === 'geometry') {
const feature = this.getFeatureFromMetadata(metadata, value)
const feature = this.getFeatureFromMetadata(metadata)
feature.geometry = value
} else {
this.updateObjectValue(feature, key, value)

View file

@ -421,9 +421,11 @@ def test_should_sync_datalayers(new_page, asgi_live_server, tilelayer):
1
).click()
# Now peerA saves the layer 2 to the server
with peerA.expect_response(re.compile(".*/datalayer/update/.*")):
peerA.get_by_role("button", name="Save").click()
# Peer A should not be in dirty state
expect(peerA.locator("body")).not_to_have_class(re.compile(".*umap-is-dirty.*"))
# Peer A should only have two markers
expect(peerA.locator(".leaflet-marker-icon")).to_have_count(2)
assert DataLayer.objects.count() == 2