diff options
author | Bharat Mediratta <bharat@menalto.com> | 2009-04-05 03:54:08 +0000 |
---|---|---|
committer | Bharat Mediratta <bharat@menalto.com> | 2009-04-05 03:54:08 +0000 |
commit | 846fc51f612997efbee1e5a0d05b773b5a4c7f73 (patch) | |
tree | 620b6f7ef37fb408183b7e4f26ad386b7dc7d191 /modules/exif/helpers | |
parent | 7d712ecd9629de7f15f79a175fd95866e75645ac (diff) |
Optimization: add all exif/iptc keys in a single insert, instead of
many separate queries.
In the process, rip out the summary column, we weren't using it.
Clean up the test, and drop the exif_records database on uninstall.
Diffstat (limited to 'modules/exif/helpers')
-rw-r--r-- | modules/exif/helpers/exif.php | 40 | ||||
-rw-r--r-- | modules/exif/helpers/exif_installer.php | 4 |
2 files changed, 22 insertions, 22 deletions
diff --git a/modules/exif/helpers/exif.php b/modules/exif/helpers/exif.php index 50a772b5..92b43df7 100644 --- a/modules/exif/helpers/exif.php +++ b/modules/exif/helpers/exif.php @@ -30,17 +30,17 @@ class exif_Core { // Only try to extract EXIF from photos if ($item->is_photo() && $item->mime_type == "image/jpeg") { + $db = Database::instance(); + $data = array(); require_once(MODPATH . "exif/lib/exif.php"); $exif_raw = read_exif_data_raw($item->file_path(), false); if (isset($exif_raw['ValidEXIFData'])) { foreach(self::_keys() as $field => $exifvar) { if (isset($exif_raw[$exifvar[0]][$exifvar[1]])) { - $exif_key = ORM::factory("exif_key"); - $exif_key->item_id = $item->id; - $exif_key->name = $field; - $exif_key->value = $exif_raw[$exifvar[0]][$exifvar[1]]; - $exif_key->summary = $exifvar[3]; - $exif_key->save(); + $data[] = sprintf( + "(%d, '%s', '%s')", + $item->id, $db->escape_str($field), + $db->escape_str($exif_raw[$exifvar[0]][$exifvar[1]])); } } } @@ -49,15 +49,19 @@ class exif_Core { $iptc = iptcparse($info["APP13"]); foreach (array("Keywords" => "2#025", "Caption" => "2#120") as $keyword => $iptc_key) { if (!empty($iptc[$iptc_key])) { - $exif_key = ORM::factory("exif_key"); - $exif_key->item_id = $item->id; - $exif_key->name = $keyword; - $exif_key->value = implode(" ", $iptc[$iptc_key]); - $exif_key->summary = false; - $exif_key->save(); + $data[] = sprintf( + "(%d, '%s', '%s')", + $item->id, $db->escape_str($keyword), + $db->escape_str(implode(" ", $iptc[$iptc_key]))); } } } + + // ORM and Database::insert() do not handle inserting multiple rows at once, so do it + // the hard way. + $query = "INSERT INTO {exif_keys} (`item_id`, `name`, `value`) VALUES" . + join(",", $data); + $db->query($query); } $record = ORM::factory("exif_record")->where("item_id", $item->id)->find(); @@ -68,14 +72,11 @@ class exif_Core { $record->save(); } - static function get($item, $summary=true) { + static function get($item) { $exif = array(); - $exif_key = ORM::factory("exif_key") - ->where("item_id", $item->id); - if ($summary) { - $exif_key->where("summary", $summary); - } - $keys = $exif_key->find_all(); + $keys = ORM::factory("exif_key") + ->where("item_id", $item->id) + ->find_all(); $definitions = self::_keys(); foreach ($keys as $key) { $exif[] = array("caption" => $definitions[$key->name][2], "value" => $key->value); @@ -84,7 +85,6 @@ class exif_Core { return $exif; } - private static function _keys() { if (!isset(self::$exif_keys)) { self::$exif_keys = array( diff --git a/modules/exif/helpers/exif_installer.php b/modules/exif/helpers/exif_installer.php index 80990917..b0173e41 100644 --- a/modules/exif/helpers/exif_installer.php +++ b/modules/exif/helpers/exif_installer.php @@ -27,10 +27,9 @@ class exif_installer { `id` int(9) NOT NULL auto_increment, `item_id` int(9) NOT NULL, `name` varchar(64) NOT NULL, - `summary` boolean NOT NULL, `value` varchar(1024) NOT NULL, PRIMARY KEY (`id`), - UNIQUE KEY(`item_id`, `summary`, `name`)) + UNIQUE KEY(`item_id`, `name`)) ENGINE=InnoDB DEFAULT CHARSET=utf8;"); $db->query("CREATE TABLE IF NOT EXISTS {exif_records} ( `id` int(9) NOT NULL auto_increment, @@ -45,6 +44,7 @@ class exif_installer { static function uninstall() { $db = Database::instance(); $db->query("DROP TABLE IF EXISTS {exif_keys};"); + $db->query("DROP TABLE IF EXISTS {exif_records};"); module::delete("exif"); } } |