]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
Bug 305333: Move attachments.thedata to its own table
authorbugreport%peshkin.net <>
Sat, 27 Aug 2005 06:11:30 +0000 (06:11 +0000)
committerbugreport%peshkin.net <>
Sat, 27 Aug 2005 06:11:30 +0000 (06:11 +0000)
Patch by Joel Peshkin <bugreport@peshkin.net>
r=lpsolit, a=justdave

Bugzilla/Attachment.pm
Bugzilla/DB/Schema.pm
Bugzilla/Search.pm
Bugzilla/Search/Quicksearch.pm
attachment.cgi
checksetup.pl
contrib/bug_email.pl
contrib/cmdline/query.conf
contrib/gnatsparse/gnatsparse.py
contrib/jb2bz.py
template/en/default/pages/quicksearchhack.html.tmpl

index 78f4ceed56bc93c10eaa424c6d8c60720672ce12..558d7f8bce37fb6219c73d3a8488f51e75146cb5 100644 (file)
@@ -78,6 +78,8 @@ sub query
                                       isobsolete, isprivate, LENGTH(thedata),
                                       submitter_id
                                       FROM attachments
+                                      INNER JOIN attach_data
+                                      ON id = attach_id
                                       WHERE bug_id = ? ORDER BY attach_id",
                                       undef, $bugid);
 
index 3e86cc50d0c79b4a10d076e20c4cf54d8ca60824..e77e6d85b5a39f9badefa986851309d96736c09e 100644 (file)
@@ -301,7 +301,6 @@ use constant ABSTRACT_SCHEMA => {
             mimetype     => {TYPE => 'MEDIUMTEXT', NOTNULL => 1},
             ispatch      => {TYPE => 'BOOLEAN'},
             filename     => {TYPE => 'varchar(100)', NOTNULL => 1},
-            thedata      => {TYPE => 'LONGBLOB', NOTNULL => 1},
             submitter_id => {TYPE => 'INT3', NOTNULL => 1},
             isobsolete   => {TYPE => 'BOOLEAN', NOTNULL => 1,
                              DEFAULT => 'FALSE'},
@@ -314,6 +313,13 @@ use constant ABSTRACT_SCHEMA => {
             attachments_submitter_id_idx => ['submitter_id', 'bug_id'],
         ],
     },
+    attach_data => {
+        FIELDS => [
+            id      => {TYPE => 'INT3', NOTNULL => 1,
+                        PRIMARYKEY => 1},
+            thedata => {TYPE => 'LONGBLOB', NOTNULL => 1},
+        ],
+    },
 
     duplicates => {
         FIELDS => [
index f30fe733b0e8453a022e1d16d1918563fcb4c89c..64342d17c67a1e406ae9905a24250c65b18cb893 100644 (file)
@@ -756,6 +756,19 @@ sub init {
                     "ON groups_$chartid.id = bug_group_map_$chartid.group_id");
             $f = "groups_$chartid.name";
          },
+         "^attach_data\.thedata," => sub {
+             my $atable = "attachments_$chartid";
+             my $dtable = "attachdata_$chartid";
+             my $extra = "";
+             if (Param("insidergroup") && !UserInGroup(Param("insidergroup"))) {
+                 $extra = "AND $atable.isprivate = 0";
+             }
+             push(@supptables, "INNER JOIN attachments AS $atable " .
+                               "ON bugs.bug_id = $atable.bug_id $extra");
+             push(@supptables, "INNER JOIN attach_data AS $dtable " .
+                               "ON $dtable.id = $atable.attach_id");
+             $f = "$dtable.thedata";
+         },
          "^attachments\..*," => sub {
              my $table = "attachments_$chartid";
              my $extra = "";
index 9f67245072d1cba9e76d3d85841721d2abb2e4c6..365e5646923651ce046aa8eef05ca51e42eba0d0 100644 (file)
@@ -80,8 +80,8 @@ my %mappings = (# Status, Resolution, Platform, OS, Priority, Severity
                 "attachment" => "attachments.description",
                 "attachmentdesc" => "attachments.description",
                 "attachdesc" => "attachments.description",
-                "attachmentdata" => "attachments.thedata",
-                "attachdata" => "attachments.thedata",
+                "attachmentdata" => "attach_data.thedata",
+                "attachdata" => "attach_data.thedata",
                 "attachmentmimetype" => "attachments.mimetype",
                 "attachmimetype" => "attachments.mimetype");
 
index eec1e0a2e90b399704bd75b2f8c6992865a945e6..86cd1698d32a6c7aa4704404eb12e9f64a3a4261 100755 (executable)
@@ -472,6 +472,7 @@ sub view
 
     # Retrieve the attachment content and its content type from the database.
     SendSQL("SELECT mimetype, filename, thedata FROM attachments " .
+            "INNER JOIN attach_data ON id = attach_id " .
             "WHERE attach_id = $attach_id");
     my ($contenttype, $filename, $thedata) = FetchSQLData();
    
@@ -595,7 +596,11 @@ sub get_unified_diff
   require File::Temp;
 
   # Get the patch
-  SendSQL("SELECT bug_id, description, ispatch, thedata FROM attachments WHERE attach_id = $id");
+  SendSQL("SELECT bug_id, description, ispatch, thedata " . 
+          "FROM attachments " .
+          "INNER JOIN attach_data " .
+          "ON id = attach_id " .
+          "WHERE attach_id = $id");
   my ($bugid, $description, $ispatch, $thedata) = FetchSQLData();
   if (!$ispatch) {
     $vars->{'attach_id'} = $id;
@@ -726,6 +731,7 @@ sub diff
 
   # Get patch data
   SendSQL("SELECT bug_id, description, ispatch, thedata FROM attachments " .
+          "INNER JOIN attach_data ON id = attach_id " .
           "WHERE attach_id = $attach_id");
   my ($bugid, $description, $ispatch, $thedata) = FetchSQLData();
 
@@ -797,7 +803,10 @@ sub viewall
             $dbh->sql_date_format('creation_ts', '%Y.%m.%d %H:%i') . ",
             mimetype, description, ispatch, isobsolete, isprivate, 
             LENGTH(thedata)
-            FROM attachments WHERE bug_id = $bugid $privacy 
+            FROM attachments 
+            INNER JOIN attach_data
+            ON attach_id = id
+            WHERE bug_id = $bugid $privacy 
             ORDER BY attach_id");
   my @attachments; # the attachments array
   while (MoreSQLData())
@@ -945,19 +954,23 @@ sub insert
 
   # Insert the attachment into the database.
   my $sth = $dbh->prepare("INSERT INTO attachments
-      (thedata, bug_id, creation_ts, filename, description,
+      (bug_id, creation_ts, filename, description,
        mimetype, ispatch, isprivate, submitter_id) 
-      VALUES (?, $bugid, $sql_timestamp, $sql_filename,
+      VALUES ($bugid, $sql_timestamp, $sql_filename,
               $description, $contenttype, " . $cgi->param('ispatch') . ",
               $isprivate, $userid)");
+  $sth->execute();
+  # Retrieve the ID of the newly created attachment record.
+  my $attachid = $dbh->bz_last_key('attachments', 'attach_id');
+
   # We only use $data here in this INSERT with a placeholder,
   # so it's safe.
+  $sth = $dbh->prepare("INSERT INTO attach_data
+                           (id, thedata) VALUES ($attachid, ?)");
   trick_taint($data);
   $sth->bind_param(1, $data, $dbh->BLOB_TYPE);
   $sth->execute();
 
-  # Retrieve the ID of the newly created attachment record.
-  my $attachid = $dbh->bz_last_key('attachments', 'attach_id');
 
   # If the file is to be stored locally, stream the file from the webserver
   # to the local file without reading it into a local variable.
@@ -1083,7 +1096,10 @@ sub edit
 
   # Retrieve the attachment from the database.
   SendSQL("SELECT description, mimetype, filename, bug_id, ispatch, isobsolete, isprivate, LENGTH(thedata)
-           FROM attachments WHERE attach_id = $attach_id");
+           FROM attachments
+           INNER JOIN attach_data
+           ON id = attach_id
+           WHERE attach_id = $attach_id");
   my ($description, $contenttype, $filename, $bugid, $ispatch, $isobsolete, $isprivate, $datasize) = FetchSQLData();
 
   my $isviewable = isViewable($contenttype);
index 7e57587a55360cb521d7c07748af89efe0430504..5fe6cea976b972a03abed47dfeb99138c15da8ac 100755 (executable)
@@ -1702,7 +1702,6 @@ AddFDef("cc", "CC", 1);
 AddFDef("dependson", "BugsThisDependsOn", 1);
 AddFDef("blocked", "OtherBugsDependingOnThis", 1);
 AddFDef("attachments.description", "Attachment description", 0);
-AddFDef("attachments.thedata", "Attachment data", 0);
 AddFDef("attachments.filename", "Attachment filename", 0);
 AddFDef("attachments.mimetype", "Attachment mime type", 0);
 AddFDef("attachments.ispatch", "Attachment is patch", 0);
@@ -1740,6 +1739,9 @@ AddFDef("percentage_complete", "Percentage Complete", 0);
 
 AddFDef("content", "Content", 0);
 
+$dbh->do("DELETE FROM fielddefs WHERE name='attachments.thedata'");
+AddFDef("attach_data.thedata", "Attachment data", 0);
+
 ###########################################################################
 # Detect changed local settings
 ###########################################################################
@@ -4009,6 +4011,27 @@ if ($dbh->bz_index_info('attachments', 'attachments_submitter_id_idx')
 $dbh->bz_add_index('attachments', 'attachments_submitter_id_idx',
                    [qw(submitter_id bug_id)]);
 
+# 2005-08-25 - bugreport@peshkin.net - Bug 305333
+if ($dbh->bz_column_info("attachments", "thedata")) {
+    print "Migrating attachment data to its own table...\n";
+    print "(This may take a very long time)\n";
+    my $sth_get1 = $dbh->prepare("SELECT attach_id 
+                                   FROM attachments");
+    my $sth_get2 = $dbh->prepare("SELECT thedata 
+                                   FROM attachments WHERE attach_id = ?");
+    $sth_get1->execute();
+    while (my ($id) = $sth_get1->fetchrow_array) {
+        $sth_get2->execute($id);
+        my ($thedata) = $sth_get2->fetchrow_array;
+        my $sth_put = $dbh->prepare("INSERT INTO attach_data
+                                     (id, thedata) VALUES ($id, ?)");
+        $sth_put->bind_param(1, $thedata, $dbh->BLOB_TYPE);
+        $sth_put->execute();
+    }
+    $dbh->bz_drop_column("attachments", "thedata");    
+}
+
+
 # If you had to change the --TABLE-- definition in any way, then add your
 # differential change code *** A B O V E *** this comment.
 #
@@ -4134,7 +4157,6 @@ add_setting ('csv_colsepchar', {',' => 1, ';' => 2 }, ',' );
 # Create Administrator  --ADMIN--
 ###########################################################################
 
-
 sub bailout {   # this is just in case we get interrupted while getting passwd
     if ($^O !~ /MSWin32/i) {
         system("stty","echo"); # re-enable input echoing
index 1590387e65da8a7b7b9e2c7bf7734483b1970442..98b8d157e2340d12d8f9fa7d9037d8fde917a26c 100755 (executable)
@@ -38,7 +38,7 @@
 #
 # You need to work with bug_email.pl the MIME::Parser installed.
 # 
-# $Id: bug_email.pl,v 1.28 2005/07/08 02:31:43 mkanat%kerio.com Exp $
+# $Id: bug_email.pl,v 1.29 2005/08/26 23:11:32 bugreport%peshkin.net Exp $
 ###############################################################
 
 # 02/12/2000 (SML)
@@ -164,14 +164,16 @@ sub storeAttachments( $$ )
 
 
         # Make SQL-String
-        my $sql = "insert into attachments (bug_id, creation_ts, description, mimetype, ispatch, filename, thedata, submitter_id) values (";
+        my $sql = "insert into attachments (bug_id, creation_ts, description, mimetype, ispatch, filename, submitter_id) values (";
         $sql .= "$bugid, now(), " . SqlQuote( $description ) . ", ";
         $sql .= SqlQuote( $mime ) . ", ";
         $sql .= "0, ";
         $sql .= SqlQuote( $decoded_file ) . ", ";
-        $sql .= SqlQuote( $data ) . ", ";
         $sql .= "$submitter_id );";
         SendSQL( $sql ) unless( $test );
+        $sql = "insert into attach_data (id, thedata) values (LAST_INSERT_ID(), ";
+        $sql .= SqlQuote( $data ) . ")";
+        SendSQL( $sql ) unless( $test );
     }
     
     return( $att_count );
index a44347b2b94a95e6ff67cf26491f7bf04e032a1b..87390cd3f852bab1073aec54fb3e083f3a948685 100644 (file)
@@ -43,7 +43,7 @@ bug_file_loc            substring       "u","url"
 status_whiteboard       substring       "w","whiteboard"
 keywords                substring       "k","K","keywords"
 attachments.description substring       "attachdesc"
-attachments.thedata     substring       "attachdata"
+attach_data.thedata     substring       "attachdata"
 attachments.mimetype    substring       "attachmime"
 dependson               substring       # bug 30823
 blocked                 substring       # bug 30823
index 5f7cde713f54b3924c1b789ab3b03d71e413c882..b317b240d187631d4314d4ff1a6ad39dd356a4b1 100755 (executable)
@@ -451,7 +451,7 @@ class Bugzillabug(object):
             print >>outfile, "  %s, %s, %s, %s);" % (id, who, when, text)
         for name, data, who in self.attachments:
             print >>outfile, "\ninsert into attachments ("
-            print >>outfile, "  bug_id, filename, description, mimetype, ispatch, submitter_id, thedata) values ("
+            print >>outfile, "  bug_id, filename, description, mimetype, ispatch, submitter_id) values ("
            ftype = None
            # It's *magic*!
            if name.endswith(".ii") == 1:
@@ -463,7 +463,10 @@ class Bugzillabug(object):
             if ftype is None:
                 ftype = "application/octet-stream"
             
-            print >>outfile, "%s,%s,%s, %s,0, %s,%s);" %(self.bug_id, SqlQuote(name), SqlQuote(name), SqlQuote (ftype), who, SqlQuote(zlib.compress(data)))
+            print >>outfile, "%s,%s,%s, %s,0, %s,%s);" %(self.bug_id, SqlQuote(name), SqlQuote(name), SqlQuote (ftype), who)
+            print >>outfile, "\ninsert into attach_data ("
+            print >>outfile, "\n(id, thedata) values (last_insert_id(),"
+            print >>outfile, "%s);" % (SqlQuote(zlib.compress(data)))
         for newstate, oldstate, fieldid, changedby, changedwhen in self.bug_activity:
             print >>outfile, "\ninsert into bugs_activity ("
             print >>outfile, "  bug_id, who, bug_when, fieldid, added, removed) values ("
index ed8231dfc7ce0aa6737fc5b9989c4a302716f305..e2f50292743ccdf5571525a01f8c4b5bb7648ae9 100644 (file)
@@ -248,10 +248,13 @@ def process_jitterbug(filename):
     for a in current['attachments']:
         cursor.execute( "INSERT INTO attachments SET " \
                         "bug_id=%s, creation_ts=%s, description='', mimetype=%s," \
-                        "filename=%s, thedata=%s, submitter_id=%s",
+                        "filename=%s, submitter_id=%s",
                         [ current['number'],
                           time.strftime("%Y-%m-%d %H:%M:%S", current['date-reported'][:9]),
-                          a[1], a[0], a[2], reporter ])
+                          a[1], a[0], reporter ])
+        cursor.execute( "INSERT INTO attach_data SET " \
+                        "id=LAST_INSERT_ID(), thedata=%s",
+                        [ a[2] ])
 
     cursor.close()
     db.close()
index 5294849915649c8c227e62710b89a4024c135fe1..22913ec4227a55e0db757f280d46ded955eb17a2 100644 (file)
   <td>&nbsp;</td>
   <td><tt>attachmentdata</tt></td>
   <td><tt>attachdata</tt></td>
-  <td>Attachment Data <i>(&ldquo;attachments.thedata&rdquo;)</i></td>
+  <td>Attachment Data <i>(&ldquo;attach_data.thedata&rdquo;)</i></td>
 </tr>
 <tr>
   <td>&nbsp;</td>