From: Michael J. Rubinsky Date: Mon, 19 Apr 2010 15:19:59 +0000 (-0400) Subject: Use a more effecient implementation for the sql driver. X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=bb45b4845e3ccdbb782d600e58761c5990c85a55;p=horde.git Use a more effecient implementation for the sql driver. --- diff --git a/framework/History/lib/Horde/History.php b/framework/History/lib/Horde/History.php index 93787fc79..715104e3d 100644 --- a/framework/History/lib/Horde/History.php +++ b/framework/History/lib/Horde/History.php @@ -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) { diff --git a/framework/History/lib/Horde/History/Sql.php b/framework/History/lib/Horde/History/Sql.php index 3e102fab1..e97cedee6 100644 --- a/framework/History/lib/Horde/History/Sql.php +++ b/framework/History/lib/Horde/History/Sql.php @@ -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. *