Revision: 2682
          https://sourceforge.net/p/mrbs/code/2682/
Author:   cimorrison
Date:     2013-02-05 15:45:25 +0000 (Tue, 05 Feb 2013)
Log Message:
-----------
Fixed bug whereby the repeat entry row is not deleted if you do a bulk delete 
from the Report page of all the entries in a series (see SF bugs #260)

Modified Paths:
--------------
    mrbs/trunk/web/del_entry_ajax.php
    mrbs/trunk/web/mrbs_sql.inc

Modified: mrbs/trunk/web/del_entry_ajax.php
===================================================================
--- mrbs/trunk/web/del_entry_ajax.php   2013-02-04 16:36:48 UTC (rev 2681)
+++ mrbs/trunk/web/del_entry_ajax.php   2013-02-05 15:45:25 UTC (rev 2682)
@@ -9,7 +9,8 @@
 //
 // If deleting lots of entries you may need to split the Ajax requests into
 // multiple smaller requests in order to avoid exceeding the system limit 
-// for POST requests.
+// for POST requests, and also the limit on the size of the SQL query once
+// the ids are imploded.
 //
 // Note that:
 // (1) the code assumes that you are an admin with powers to delete anything.
@@ -47,9 +48,25 @@
   }
 }
 
+
 // Everything looks OK - go ahead and delete the entries
+
+// Note on performance.   It is much quicker to delete entries using the
+// WHERE id IN method below than looping through mrbsDelEntry().  Testing
+// for 100 entries gave 2.5ms for the IN method against 37.6s for the looping
+// method - ie approx 15 times faster.   For 1,000 rows the IN method was 19
+// times faster.
+//
+// Because we are not using mrbsDelEntry() we have to delete any orphaned
+// rows in the repeat table ourselves - but this does not take long.
+
 $sql = "DELETE FROM $tbl_entry WHERE id IN (" . implode(',', $ids) . ")";
 $result = sql_command($sql);
 
+// And delete any orphaned rows in the repeat table
+$sql = "DELETE FROM $tbl_repeat WHERE id NOT IN (SELECT repeat_id FROM 
$tbl_entry)";
+$orphan_result = sql_command($sql);
+
+
 echo $result;
 ?>
\ No newline at end of file

Modified: mrbs/trunk/web/mrbs_sql.inc
===================================================================
--- mrbs/trunk/web/mrbs_sql.inc 2013-02-04 16:36:48 UTC (rev 2681)
+++ mrbs/trunk/web/mrbs_sql.inc 2013-02-05 15:45:25 UTC (rev 2682)
@@ -380,7 +380,8 @@
 
 /** mrbsDelEntry()
  * 
- * Delete an entry, or optionally all entries.
+ * Delete an entry, or optionally all entries.   Will also delete any newly
+ * orphaned rows in the repeat table.
  * 
  * $user   - Who's making the request
  * $id     - The entry to delete
@@ -388,7 +389,7 @@
  * $all    - If set, include user modified entries in the series delete
  *
  * Returns FALSE if an error occured, otherwise an array of start_times that
- * have been deleted
+ * have been deleted.
  *
  */
 function mrbsDelEntry($user, $id, $series, $all)
@@ -445,8 +446,9 @@
     }
   }
 
+  // Get rid of any orphaned rows in the repeat table
   if ($repeat_id > 0 &&
-      sql_query1("SELECT count(*) FROM $tbl_entry WHERE repeat_id=$repeat_id") 
== 0)
+      sql_query1("SELECT COUNT(*) FROM $tbl_entry WHERE repeat_id=$repeat_id") 
== 0)
   {
     sql_command("DELETE FROM $tbl_repeat WHERE id=$repeat_id");
   }
@@ -455,6 +457,7 @@
   return $start_times;
 }
 
+
 /** mrbsCreateEntry()
  * 
  * Create an entry in the database
------------------------------------------------------------------------------
Free Next-Gen Firewall Hardware Offer
Buy your Sophos next-gen firewall before the end March 2013 
and get the hardware for free! Learn more.
http://p.sf.net/sfu/sophos-d2d-feb
_______________________________________________
Mrbs-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mrbs-commits

Reply via email to