make sure there no local cache problems when a changeset change is reverted
This commit is contained in:
parent
b3f307b9a6
commit
7431bac30a
2 changed files with 25 additions and 13 deletions
|
@ -322,16 +322,17 @@ class EditorViewSet(EditorViewSetMixin, ViewSet):
|
||||||
|
|
||||||
return Response({
|
return Response({
|
||||||
'update_cache_key': update_cache_key,
|
'update_cache_key': update_cache_key,
|
||||||
'geometries': [
|
'geometries': [self.conditional_geojson(obj, update_cache_key_match) for obj in results],
|
||||||
(
|
|
||||||
obj.get_geojson_key()
|
|
||||||
if update_cache_key_match and not obj._affected_by_changeset
|
|
||||||
else obj.to_geojson(instance=obj)
|
|
||||||
)
|
|
||||||
for obj in results
|
|
||||||
],
|
|
||||||
})
|
})
|
||||||
|
|
||||||
|
def conditional_geojson(self, obj, update_cache_key_match):
|
||||||
|
if update_cache_key_match and not obj._affected_by_changeset:
|
||||||
|
return obj.get_geojson_key()
|
||||||
|
|
||||||
|
result = obj.to_geojson(instance=obj)
|
||||||
|
result['properties']['changed'] = obj._affected_by_changeset
|
||||||
|
return result
|
||||||
|
|
||||||
@action(detail=False, methods=['get'])
|
@action(detail=False, methods=['get'])
|
||||||
@api_etag(etag_func=MapUpdate.current_cache_key, cache_parameters={})
|
@api_etag(etag_func=MapUpdate.current_cache_key, cache_parameters={})
|
||||||
def geometrystyles(self, request, *args, **kwargs):
|
def geometrystyles(self, request, *args, **kwargs):
|
||||||
|
|
|
@ -675,7 +675,7 @@ editor = {
|
||||||
_last_geometry_cache: {},
|
_last_geometry_cache: {},
|
||||||
load_geometries: function (geometry_url, highlight_type, editing_id) {
|
load_geometries: function (geometry_url, highlight_type, editing_id) {
|
||||||
// load geometries from url
|
// load geometries from url
|
||||||
var same_url = (editor._last_geometry_url == geometry_url);
|
var same_url = (editor._last_geometry_url === geometry_url);
|
||||||
editor._last_geometry_url = geometry_url;
|
editor._last_geometry_url = geometry_url;
|
||||||
editor._loading_geometry = true;
|
editor._loading_geometry = true;
|
||||||
editor._highlight_type = highlight_type;
|
editor._highlight_type = highlight_type;
|
||||||
|
@ -702,12 +702,23 @@ editor = {
|
||||||
feature = result.geometries[i];
|
feature = result.geometries[i];
|
||||||
if (Array.isArray(feature)) {
|
if (Array.isArray(feature)) {
|
||||||
// load from cache
|
// load from cache
|
||||||
feature = editor._last_geometry_cache[feature[0]][feature[1]];
|
if (feature[0] in editor._last_geometry_cache) {
|
||||||
|
feature = editor._last_geometry_cache[feature[0]][feature[1]];
|
||||||
|
} else {
|
||||||
|
feature = null;
|
||||||
|
}
|
||||||
|
if (!feature) {
|
||||||
|
editor._last_geometry_update_cache_key = null;
|
||||||
|
editor.load_geometries(editor._last_geometry_url, editor._highlight_type, editor._editing_id);
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (!new_cache[feature.properties.type]) {
|
if (!feature.properties.changed) {
|
||||||
new_cache[feature.properties.type] = {};
|
if (!new_cache[feature.properties.type]) {
|
||||||
|
new_cache[feature.properties.type] = {};
|
||||||
|
}
|
||||||
|
new_cache[feature.properties.type][feature.properties.id] = feature;
|
||||||
}
|
}
|
||||||
new_cache[feature.properties.type][feature.properties.id] = feature;
|
|
||||||
geometries.push(feature);
|
geometries.push(feature);
|
||||||
}
|
}
|
||||||
editor._last_geometry_cache = new_cache;
|
editor._last_geometry_cache = new_cache;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue