From bb45b4845e3ccdbb782d600e58761c5990c85a55 Mon Sep 17 00:00:00 2001 From: "Michael J. Rubinsky" Date: Mon, 19 Apr 2010 11:19:59 -0400 Subject: [PATCH] Use a more effecient implementation for the sql driver. --- framework/History/lib/Horde/History.php | 2 -- framework/History/lib/Horde/History/Sql.php | 27 +++++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) 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. * -- 2.11.0