1111from django .core .management .base import BaseCommand
1212from django .db import connection
1313
14+ from catmaid .consumers import msg_all
1415from catmaid .control .edge import get_intersected_grid_cells
1516from catmaid .control .node import (get_configured_node_providers ,
1617 GridCachedNodeProvider , Postgis3dNodeProvider , update_grid_cell )
@@ -45,6 +46,7 @@ def update(self, updates, cursor):
4546 # Batch of grids to update during one run
4647 updated_cells = 0
4748 updated_grids = set ()
49+ updated_cell_refs = []
4850 for update in updates :
4951 g = grid_map [update ['grid_id' ]]
5052 w_i , h_i , d_i = update ['x' ], update ['y' ], update ['z' ]
@@ -61,21 +63,34 @@ def update(self, updates, cursor):
6163 if g .hidden_last_editor_id :
6264 params ['hidden_last_editor_id' ] = int (g .hidden_last_editor_id )
6365
64- added = update_grid_cell (g .project_id , g .id , w_i , h_i , d_i ,
66+ updated = update_grid_cell (g .project_id , g .id , w_i , h_i , d_i ,
6567 g .cell_width , g .cell_height , g .cell_depth ,
6668 params , g .allow_empty , g .n_lod_levels , g .lod_min_bucket_size ,
6769 g .lod_strategy , g .has_json_data , g .has_json_text_data ,
6870 g .has_msgpack_data , provider = provider , cursor = cursor ,
6971 delete_empty = True )
7072
71- if added :
73+ if updated :
7274 updated_cells += 1
7375 updated_grids .add (g .id )
76+ updated_cell_refs .add ([{
77+ 'project_id' : g .project_id ,
78+ 'grid_id' , g .id ,
79+ 'x' : w_i ,
80+ 'y' : h_i ,
81+ 'z' : d_i ,
82+ })
7483
7584 # TODO: delete in batches
7685 DirtyNodeGridCacheCell .objects .filter (grid_id = g .id , x_index = w_i ,
7786 y_index = h_i , z_index = d_i ).delete ()
7887
88+ # Optionally, let users know about updated cells
89+ if settings .SPATIAL_UPDATE_CLIENT_NOTIFICATIONS :
90+ msg_all ('grid-cache-update' , {
91+ 'updated_cells' : updated_cell_refs ,
92+ })
93+
7994 logger .debug (f'Updated { updated_cells } grid cell(s) in { len (updated_grids )} grid cache(s)' )
8095
8196
0 commit comments