about summary refs log tree commit homepage
path: root/lib/dtas/mlib.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/dtas/mlib.rb')
-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