Browse Source

fixes bug #1203 - remove reindex data feature

Damien Accorsi 10 years ago
parent
commit
33d5786e33
2 changed files with 47 additions and 22 deletions
  1. 47 14
      pboard/pboard/controllers/api.py
  2. 0 8
      pboard/pboard/templates/master.mak

+ 47 - 14
pboard/pboard/controllers/api.py View File

@@ -178,6 +178,7 @@ class PODApiController(BaseController):
178 178
     @expose()
179 179
     @require(can_write())
180 180
     def set_parent_node(self, node_id, new_parent_id, **kw):
181
+      """ @see reindex_nodes() """
181 182
       loCurrentUser   = pld.PODStaticController.getCurrentUser()
182 183
       loApiController = pld.PODUserFilteredApiController(loCurrentUser.user_id)
183 184
       
@@ -187,9 +188,25 @@ class PODApiController(BaseController):
187 188
         if new_parent_id==0:
188 189
           new_parent_id = None
189 190
         loNewNode.parent_id = int(new_parent_id)
191
+        self._updateParentTreePathForNodeAndChildren(loNewNode)
190 192
       pm.DBSession.flush()
191 193
       redirect(lurl('/document/%s'%(node_id)))
192 194
 
195
+    def _updateParentTreePathForNodeAndChildren(self, moved_node: pmd.PBNode):
196
+      """ propagate the move to all child nodes and update there node_depth and parent_tree_path properties """
197
+      parent_node = moved_node._oParent
198
+      if parent_node==None:
199
+        new_parent_tree_path = '/'
200
+        moved_node.node_depth = 0
201
+      else:
202
+        new_parent_tree_path = '{0}{1}/'.format(parent_node.parent_tree_path, parent_node.node_id)
203
+        moved_node.node_depth = parent_node.node_depth+1
204
+      moved_node.parent_tree_path = new_parent_tree_path
205
+
206
+      for child_node in moved_node._lAllChildren:
207
+        self._updateParentTreePathForNodeAndChildren(child_node)
208
+
209
+
193 210
     @expose()
194 211
     @require(can_write())
195 212
     def move_node_upper(self, node_id=0):
@@ -274,21 +291,37 @@ class PODApiController(BaseController):
274 291
 
275 292
       redirect(lurl('/document/%i'%(liParentId or 0)))
276 293
 
277
-    @expose()
278 294
     def reindex_nodes(self, back_to_node_id=0):
279
-      # FIXME - NOT SAFE
280
-      loRootNodeList   = pm.DBSession.query(pmd.PBNode).order_by(pmd.PBNode.parent_id).all()
281
-      for loNode in loRootNodeList:
282
-        if loNode.parent_id==None:
283
-          loNode.node_depth = 0
284
-          loNode.parent_tree_path = '/'
285
-        else:
286
-          loNode.node_depth = loNode._oParent.node_depth+1
287
-          loNode.parent_tree_path = '%s%i/'%(loNode._oParent.parent_tree_path,loNode.parent_id)
288
-      
289
-      pm.DBSession.flush()
290
-      flash(_('Documents re-indexed'), 'info')
291
-      redirect(lurl('/document/%s'%(back_to_node_id)))
295
+      # DA - INFO - 2014-05-26
296
+      #
297
+      #  The following query allows to detect which not are not up-to-date anymore.
298
+      # These up-to-date failure is related to the node_depth and parent_tree_path being out-dated.
299
+      # This mainly occured when "move node" feature was not working correctly.
300
+      #
301
+      # The way to fix the data is the following:
302
+      # - run mannually the following command
303
+      # - for each result, call manually /api/set_parent_node?node_id=parent_node_id&new_parent_id=parent_parent_id
304
+      #
305
+      sql_query = """
306
+        select
307
+            pn.node_id as child_node_id,
308
+            pn.parent_id as child_parent_id,
309
+            pn.parent_tree_path as child_parent_tree_path,
310
+            pn.node_depth as child_node_depth,
311
+            pnn.node_id as parent_node_id,
312
+            pnn.parent_id as parent_parent_id,
313
+            pnn.parent_tree_path as parent_parent_tree_path,
314
+            pnn.node_depth as parent_node_depth
315
+
316
+        from
317
+            pod_nodes as pn,
318
+            pod_nodes as pnn
319
+        where
320
+            pn.parent_id = pnn.node_id
321
+            and pn.parent_tree_path not like pnn.parent_tree_path||'%'
322
+      """
323
+      return 
324
+
292 325
 
293 326
     @expose()
294 327
     @require(can_write())

+ 0 - 8
pboard/pboard/templates/master.mak View File

@@ -98,14 +98,6 @@
98 98
               <a title="${_('Toggle view mode: large')}"  id='view-size-toggle-button-large' class="pod-do-not-display"><i class='fa fa-eye'></i></a>
99 99
             </li>
100 100
 
101
-            <li title="Rebuild document index">
102
-            % if current_node is UNDEFINED or current_node==None:
103
-              <a href="${tg.url('/api/reindex_nodes?back_to_node_id=0')}"><i class="fa fa-refresh"></i></a>
104
-            % else:
105
-              <a href="${tg.url('/api/reindex_nodes?back_to_node_id=%i'%(current_node.node_id))}"><i class="fa fa-refresh"></i></a>
106
-            % endif
107
-            </li>
108
-
109 101
 ##            <li class="dropdown" title="Calculator">
110 102
 ##              <a href="#" class="dropdown-toggle" data-toggle="dropdown"><i class="icon-g-calculator"></i></a>
111 103
 ##              <ul class="dropdown-menu pull-left">