about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2016-01-17 08:28:56 +0000
committerEric Wong <e@80x24.org>2016-01-17 08:28:56 +0000
commitbb84ca40164b57281f1a58d7a06e28a421fe6fbb (patch)
treee33498b976dca8fc5c0c51803096c554965e4c6f
parentcb5a016bf5e1288e6ec3afea4dc79381576b572e (diff)
downloaddtas-bb84ca40164b57281f1a58d7a06e28a421fe6fbb.tar.gz
We need to ensure children and comments are all deleted before
parents are.
-rw-r--r--lib/dtas/mlib.rb14
1 files changed, 12 insertions, 2 deletions
diff --git a/lib/dtas/mlib.rb b/lib/dtas/mlib.rb
index fddf8ad..1f61369 100644
--- a/lib/dtas/mlib.rb
+++ b/lib/dtas/mlib.rb
@@ -430,15 +430,25 @@ class DTAS::Mlib # :nodoc:
     node_id = node[:id]
     q = { parent_id: node_id }
     nodes = @db[:nodes]
+    comments = @db[:comments]
+
+    # remove children, step 1
     nodes.where(q).each do |nd|
-      next if nd[:id] == root_id
+      nd_id = nd[:id]
+      next if nd_id == root_id
       case nd[:tlen]
       when DM_DIR, DM_IGN
         remove_entry(nd)
+      else
+        comments.where(node_id: nd_id).delete
       end
     end
+
+    # remove children, step 2
     nodes.where(q).delete
-    @db[:comments].where(node_id: node_id).delete
+
+    # finally remove ourselves
+    comments.where(node_id: node_id).delete
     nodes.where(id: node_id).delete
   end