From 9d97b1243a78e8703fefb2a1da2794a6434912c4 Mon Sep 17 00:00:00 2001 From: "Steinar H. Gunderson" Date: Tue, 21 Aug 2007 07:12:06 +0200 Subject: [PATCH] Add model/lens fields to the images table, and make upgrade code to populate the fields. Also make update_image_info() populate them on new uploads etc. The idea is to get rid of all SELECTs against exif_info, as EAV is quite evil and is not needed in this case. --- perl/Sesse/pr0n/Common.pm | 21 +++++++++++++++++---- sql/pr0n.sql | 4 ++++ sql/upgrade-v2.50.sql | 15 +++++++++++++++ 3 files changed, 36 insertions(+), 4 deletions(-) diff --git a/perl/Sesse/pr0n/Common.pm b/perl/Sesse/pr0n/Common.pm index dcaf244..eff6fc1 100644 --- a/perl/Sesse/pr0n/Common.pm +++ b/perl/Sesse/pr0n/Common.pm @@ -244,10 +244,6 @@ sub update_image_info { { local $dbh->{AutoCommit} = 0; - $dbh->do('UPDATE images SET width=?, height=?, date=? WHERE id=?', - undef, $width, $height, $datetime, $id) - or die "Couldn't update width/height in SQL: $!"; - # EXIF information $dbh->do('DELETE FROM exif_info WHERE image=?', undef, $id) @@ -262,6 +258,22 @@ sub update_image_info { or die "Couldn't insert EXIF information in database: $!"; } + # Model/Lens + my $model = $exiftool->GetValue('Model', 'ValueConv'); + my $lens = $exiftool->GetValue('Lens', 'ValueConv'); + $lens = $exiftool->GetValue('LensSpec', 'ValueConv') if (!defined($lens)); + + $model =~ s/^\s*//; + $model =~ s/\s*$//; + + $lens =~ s/^\s*//; + $lens =~ s/\s*$//; + + # Now update the main table with the information we've got + $dbh->do('UPDATE images SET width=?, height=?, date=?, model=?, lens=? WHERE id=?', + undef, $width, $height, $datetime, $model, $lens, $id) + or die "Couldn't update width/height in SQL: $!"; + # Tags my @tags = $exiftool->GetValue('Keywords', 'ValueConv'); $dbh->do('DELETE FROM tags WHERE image=?', @@ -271,6 +283,7 @@ sub update_image_info { $q = $dbh->prepare('INSERT INTO tags (image,tag) VALUES (?,?)') or die "Couldn't prepare inserting tag information: $!"; + for my $tag (@tags) { $q->execute($id, guess_charset($tag)) or die "Couldn't insert tag information in database: $!"; diff --git a/sql/pr0n.sql b/sql/pr0n.sql index 5fd04e7..d6af636 100644 --- a/sql/pr0n.sql +++ b/sql/pr0n.sql @@ -29,6 +29,8 @@ CREATE TABLE images ( "date" timestamp without time zone, takenby character varying NOT NULL, selected boolean DEFAULT false, + model character varying, + lens character varying, FOREIGN KEY (vhost,event) REFERENCES events (vhost,event) ); @@ -71,6 +73,8 @@ CREATE TABLE users ( vhost character varying NOT NULL ); +-- Mainly used for manual queries -- usually too slow to be very useful +-- for web views in the long run. CREATE TABLE exif_info ( image integer NOT NULL REFERENCES images (id) ON DELETE CASCADE, key varchar NOT NULL, diff --git a/sql/upgrade-v2.50.sql b/sql/upgrade-v2.50.sql index d59ee9e..99cc11d 100644 --- a/sql/upgrade-v2.50.sql +++ b/sql/upgrade-v2.50.sql @@ -31,3 +31,18 @@ ALTER TABLE deleted_images ALTER COLUMN width SET DEFAULT NULL; ALTER TABLE deleted_images ALTER COLUMN height SET DEFAULT NULL; UPDATE deleted_images SET width=NULL,height=NULL WHERE width=-1 OR height=-1; ALTER TABLE deleted_images ADD CONSTRAINT width_height_nullity CHECK ((width IS NULL) = (height IS NULL)); + +-- model/lens denormalization (reduce usage of exif_info) +ALTER TABLE images ADD COLUMN model varchar; +ALTER TABLE images ADD COLUMN lens varchar; +UPDATE images SET lens=COALESCE( + TRIM(( + SELECT value FROM exif_info WHERE key='Lens' AND images.id=exif_info.image + )), + TRIM(( + SELECT value FROM exif_info WHERE key='LensSpec' AND images.id=exif_info.image + )) +), model=TRIM(( + SELECT value FROM exif_info WHERE key='Model' AND images.id=exif_info.image +)); + -- 2.39.2