Use a more effecient implementation for the sql driver.
authorMichael J. Rubinsky <mrubinsk@horde.org>
Mon, 19 Apr 2010 15:19:59 +0000 (11:19 -0400)
committerMichael J. Rubinsky <mrubinsk@horde.org>
Mon, 19 Apr 2010 15:19:59 +0000 (11:19 -0400)
framework/History/lib/Horde/History.php
framework/History/lib/Horde/History/Sql.php

index 93787fc..715104e 100644 (file)
@@ -248,8 +248,6 @@ abstract class Horde_History
             throw new InvalidArgumentException('$guid and $action need to be strings!');
         }
 
-        /* This implementation still works, but we should be able to get much
-         * faster now with a SELECT MAX(history_ts) ... query. */
         try {
             $history = $this->getHistory($guid);
         } catch (Horde_History_Exception $e) {
index 3e102fa..e97cede 100644 (file)
@@ -73,6 +73,33 @@ class Horde_History_Sql extends Horde_History
     }
 
     /**
+     * Gets the timestamp of the most recent change to $guid.
+     *
+     * @param string $guid   The name of the history entry to retrieve.
+     * @param string $action An action: 'add', 'modify', 'delete', etc.
+     *
+     * @return integer  The timestamp, or 0 if no matching entry is found.
+     *
+     * @throws InvalidArgumentException If the input parameters are not of
+     *                                  type string.
+     */
+    public function getActionTimestamp($guid, $action)
+    {
+        if (!is_string($guid) || !is_string($action)) {
+            throw new InvalidArgumentException('$guid and $action need to be strings!');
+        }
+
+        $result = $this->_db->getOne('SELECT MAX(history_ts) FROM horde_histories WHERE history_action = ? AND object_uid = ?', array($action, $guid));
+        try {
+            $this->handleError($result);
+        } catch (Horde_History_Exception $e) {
+            return 0;
+        }
+
+        return (int)$result;
+    }
+
+    /**
      * Logs an event to an item's history log. Any other details about the
      * event are passed in $attributes.
      *