]> git.sesse.net Git - pr0n/commitdiff
Add model/lens fields to the images table, and make upgrade code to populate
authorSteinar H. Gunderson <sesse@debian.org>
Tue, 21 Aug 2007 05:12:06 +0000 (07:12 +0200)
committerSteinar H. Gunderson <sesse@debian.org>
Tue, 21 Aug 2007 05:12:06 +0000 (07:12 +0200)
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
sql/pr0n.sql
sql/upgrade-v2.50.sql

index dcaf244af5e84330988d93c12b858de539f68d91..eff6fc13ecb991196a64fb8ea695708f1cf6d66b 100644 (file)
@@ -244,10 +244,6 @@ sub update_image_info {
        {
                local $dbh->{AutoCommit} = 0;
 
        {
                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)
                # 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: $!";
                }
 
                                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=?',
                # 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: $!";
 
                $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: $!";
                for my $tag (@tags) {
                        $q->execute($id, guess_charset($tag))
                                or die "Couldn't insert tag information in database: $!";
index 5fd04e7e9da4872719e7b1cbe9eaf257b0d53077..d6af63681a720d734254f157860489706fd3b68d 100644 (file)
@@ -29,6 +29,8 @@ CREATE TABLE images (
     "date" timestamp without time zone,
     takenby character varying NOT NULL,
     selected boolean DEFAULT false,
     "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)
 );
 
     FOREIGN KEY (vhost,event) REFERENCES events (vhost,event)
 );
@@ -71,6 +73,8 @@ CREATE TABLE users (
     vhost character varying NOT NULL
 );
 
     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,
 CREATE TABLE exif_info (
     image integer NOT NULL REFERENCES images (id) ON DELETE CASCADE,
     key varchar NOT NULL,
index d59ee9e13497a838033cb34e1cb4236d1d1b3aaa..99cc11d1d529168a7dd7f80a2829824497a01622 100644 (file)
@@ -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));
 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
+));
+