]> git.sesse.net Git - pr0n/commitdiff
Remove some really long-standing silliness: If we have no idea about width
authorSteinar H. Gunderson <sesse@debian.org>
Tue, 21 Aug 2007 04:28:51 +0000 (06:28 +0200)
committerSteinar H. Gunderson <sesse@debian.org>
Tue, 21 Aug 2007 04:28:51 +0000 (06:28 +0200)
or height, we used to have -1 as a default, and have the field NOT NULL.
SQL has a perfectly good value for "unknown data" -- it's called NULL. Make
upgrade SQL, and clean up the few code places that was used to the field being
-1.

perl/Sesse/pr0n/Common.pm
perl/Sesse/pr0n/Index.pm
sql/upgrade-v2.50.sql

index e929b654d998e8674fd141d9f0a62592d70415f1..dcaf244af5e84330988d93c12b858de539f68d91 100644 (file)
@@ -356,7 +356,7 @@ sub ensure_cached {
        my ($r, $filename, $id, $dbwidth, $dbheight, $infobox, $xres, $yres, @otherres) = @_;
 
        my $fname = get_disk_location($r, $id);
        my ($r, $filename, $id, $dbwidth, $dbheight, $infobox, $xres, $yres, @otherres) = @_;
 
        my $fname = get_disk_location($r, $id);
-       unless (defined($xres) && ($xres < $dbheight || $yres < $dbwidth || $dbwidth == -1 || $dbheight == -1 || $xres == -1)) {
+       unless (defined($xres) && ($xres < $dbheight || $yres < $dbwidth || !defined($dbwidth) || !defined($dbheight) || $xres == -1)) {
                return ($fname, 0);
        }
 
                return ($fname, 0);
        }
 
@@ -405,7 +405,7 @@ sub ensure_cached {
                my $height = $img->Get('rows');
 
                # Update the SQL database if it doesn't contain the required info
                my $height = $img->Get('rows');
 
                # Update the SQL database if it doesn't contain the required info
-               if ($dbwidth == -1 || $dbheight == -1) {
+               if (!defined($dbwidth) || !defined($dbheight)) {
                        $r->log->info("Updating width/height for $id: $width x $height");
                        update_image_info($r, $id, $width, $height);
                }
                        $r->log->info("Updating width/height for $id: $width x $height");
                        update_image_info($r, $id, $width, $height);
                }
index 2c93c7c55c93bd930d71828759558ca33fc608e3..74d5329d5cbc376207ae2e527b051c5202fa4f79 100644 (file)
@@ -199,7 +199,9 @@ sub handler {
 
                my @files = ();
                while (my $ref = $q->fetchrow_hashref()) {
 
                my @files = ();
                while (my $ref = $q->fetchrow_hashref()) {
-                       push @files, [ $ref->{'event'}, $ref->{'filename'}, $ref->{'width'}, $ref->{'height'} ];
+                       my $width = defined($ref->{'width'}) ? $ref->{'width'} : -1;
+                       my $height = defined($ref->{'height'}) ? $ref->{'height'} : -1;
+                       push @files, [ $ref->{'event'}, $ref->{'filename'}, $width, $height ];
                }
                
                for my $i (0..$#files) {
                }
                
                for my $i (0..$#files) {
@@ -366,7 +368,7 @@ sub handler {
                                }
                        }
 
                                }
                        }
 
-                       if ($ref->{'width'} != -1 && $ref->{'height'} != -1) {
+                       if (defined($ref->{'width'}) && defined($ref->{'height'})) {
                                my $width = $ref->{'width'};
                                my $height = $ref->{'height'};
                                        
                                my $width = $ref->{'width'};
                                my $height = $ref->{'height'};
                                        
index ad63bdff3b6ec4ead8bc5f57cfe3207b531d9510..0d44ba3cd700b4135cb0cb9fcd5c1c5af8505d42 100644 (file)
@@ -16,3 +16,11 @@ CREATE TABLE tags (
 CREATE INDEX tags_tag ON tags ( tag );
 
 GRANT SELECT,INSERT,DELETE ON TABLE tags TO pr0n;
 CREATE INDEX tags_tag ON tags ( tag );
 
 GRANT SELECT,INSERT,DELETE ON TABLE tags TO pr0n;
+
+-- width/height -1 => NULL
+ALTER TABLE images ALTER COLUMN width DROP NOT NULL;
+ALTER TABLE images ALTER COLUMN height DROP NOT NULL;
+ALTER TABLE images ALTER COLUMN width SET DEFAULT NULL;
+ALTER TABLE images ALTER COLUMN height SET DEFAULT NULL;
+UPDATE images SET width=NULL,height=NULL WHERE width=-1 OR height=-1;
+ALTER TABLE images ADD CONSTRAINT width_height_nullity CHECK ((width IS NULL) = (height IS NULL));