]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
Bug 1635148 - Recent changes to add support for attachments in S3 caused a memory...
authordklawren <dklawren@users.noreply.github.com>
Mon, 4 May 2020 17:37:43 +0000 (13:37 -0400)
committerGitHub <noreply@github.com>
Mon, 4 May 2020 17:37:43 +0000 (13:37 -0400)
Bugzilla/Attachment.pm
Bugzilla/Attachment/Storage/Base.pm
Bugzilla/Attachment/Storage/Database.pm
Bugzilla/Attachment/Storage/FileSystem.pm
Bugzilla/Attachment/Storage/S3.pm
extensions/PhabBugz/lib/Feed.pm

index f82808d58c5b4753a3502a96ed04c45651ca8079..12d7bd2670d40482eba9018983d54f8bb47d8309 100644 (file)
@@ -936,15 +936,15 @@ sub get_storage_by_name {
   # all options for attachment_storage need to be handled here
   if ($name eq 'database') {
     require Bugzilla::Attachment::Storage::Database;
-    return Bugzilla::Attachment::Storage::Database->new({attachment => $self});
+    return Bugzilla::Attachment::Storage::Database->new({attach_id => $self->id});
   }
   elsif ($name eq 'filesystem') {
     require Bugzilla::Attachment::Storage::FileSystem;
-    return Bugzilla::Attachment::Storage::FileSystem->new({attachment => $self});
+    return Bugzilla::Attachment::Storage::FileSystem->new({attach_id => $self->id});
   }
   elsif ($name eq 's3') {
     require Bugzilla::Attachment::Storage::S3;
-    return Bugzilla::Attachment::Storage::S3->new({attachment => $self});
+    return Bugzilla::Attachment::Storage::S3->new({attach_id => $self->id, datasize => $self->datasize});
   }
   else {
     return undef;
index 4725f05c7b3ebca897846122b958938defff48d7..780aa2da280aa96b73f7692d49c39bbdc0eedb34 100644 (file)
@@ -10,28 +10,28 @@ package Bugzilla::Attachment::Storage::Base;
 use 5.10.1;
 use Moo::Role;
 
-use Type::Utils qw(class_type);
+use Types::Standard qw(Int);
 
 requires qw(set_data get_data remove_data data_exists data_type);
 
-has 'attachment' => (
+has 'attach_id' => (
   is       => 'ro',
   required => 1,
-  isa      => class_type({class => 'Bugzilla::Attachment'})
+  isa      => Int
 );
 
 sub set_class {
   my ($self) = @_;
   Bugzilla->dbh->do(
     "REPLACE INTO attachment_storage_class (id, storage_class) VALUES (?, ?)",
-    undef, $self->attachment->id, $self->data_type);
+    undef, $self->attach_id, $self->data_type);
   return $self;
 }
 
 sub remove_class {
   my ($self) = @_;
   Bugzilla->dbh->do("DELETE FROM attachment_storage_class WHERE id = ?",
-    undef, $self->attachment->id);
+    undef, $self->attach_id);
   return $self;
 }
 
index 9da52ef6ce9aca43b98cf803ff96fe9f433f041c..22eaf762b48e1f99ac72f51fa59ae7ebda74f2dd 100644 (file)
@@ -21,7 +21,7 @@ sub set_data {
     = $dbh->prepare(
     "REPLACE INTO attach_data (id, thedata) VALUES (?, ?)"
     );
-  $sth->bind_param(1, $self->attachment->id);
+  $sth->bind_param(1, $self->attach_id);
   $sth->bind_param(2, $data, $dbh->BLOB_TYPE);
   $sth->execute();
   return $self;
@@ -32,14 +32,14 @@ sub get_data {
   my $dbh = Bugzilla->dbh;
   my ($data)
     = $dbh->selectrow_array("SELECT thedata FROM attach_data WHERE id = ?",
-    undef, $self->attachment->id);
+    undef, $self->attach_id);
   return $data;
 }
 
 sub remove_data {
   my ($self) = @_;
   my $dbh = Bugzilla->dbh;
-  $dbh->do("DELETE FROM attach_data WHERE id = ?", undef, $self->attachment->id);
+  $dbh->do("DELETE FROM attach_data WHERE id = ?", undef, $self->attach_id);
   return $self;
 }
 
@@ -47,7 +47,7 @@ sub data_exists {
   my ($self)   = @_;
   my $dbh      = Bugzilla->dbh;
   my ($exists) = $dbh->selectrow_array("SELECT 1 FROM attach_data WHERE id = ?",
-    undef, $self->attachment->id);
+    undef, $self->attach_id);
   return !!$exists;
 }
 
index 7a67d1b3c520ee56a81859768ce112e1a2f7c93d..50e7f7230132f9c180bfa0a45975c2262776a434 100644 (file)
@@ -51,13 +51,13 @@ sub data_exists {
 
 sub _local_path {
   my ($self) = @_;
-  my $hash = sprintf 'group.%03d', $self->attachment->id % 1000;
+  my $hash = sprintf 'group.%03d', $self->attach_id % 1000;
   return bz_locations()->{attachdir} . '/' . $hash;
 }
 
 sub _local_file {
   my ($self) = @_;
-  return $self->_local_path() . '/attachment.' . $self->attachment->id;
+  return $self->_local_path() . '/attachment.' . $self->attach_id;
 }
 
 1;
index aea04572cf3fc5c86e6b09a7b48ec4ff72fcf7a2..afb25e4525c720eaa872308f1c54ededa85f6e56 100644 (file)
@@ -13,10 +13,17 @@ use Moo;
 use Bugzilla::Error;
 use Bugzilla::S3;
 
+use Types::Standard qw(Int);
+
 with 'Bugzilla::Attachment::Storage::Base';
 
 has 's3'     => (is => 'lazy');
 has 'bucket' => (is => 'lazy');
+has 'datasize' => (
+  is       => 'ro',
+  required => 1,
+  isa      => Int
+);
 
 sub _build_s3 {
   my $self = shift;
@@ -38,15 +45,15 @@ sub data_type { return 's3'; }
 
 sub set_data {
   my ($self, $data) = @_;
-  my $attach_id = $self->attachment->id;
+  my $attach_id = $self->attach_id;
 
   # If the attachment is larger than attachment_s3_minsize,
   # we instead store it in the database.
   if (Bugzilla->params->{attachment_s3_minsize}
-    && $self->attachment->datasize < Bugzilla->params->{attachment_s3_minsize})
+    && $self->datasize < Bugzilla->params->{attachment_s3_minsize})
   {
     require Bugzilla::Attachment::Storage::Database;
-    return Bugzilla::Attachment::Storage::Database->new({attachment => $self->attachment})
+    return Bugzilla::Attachment::Storage::Database->new({attach_id => $self->attach_id})
       ->set_data($data);
   }
 
@@ -62,7 +69,7 @@ sub set_data {
 
 sub get_data {
   my ($self)    = @_;
-  my $attach_id = $self->attachment->id;
+  my $attach_id = $self->attach_id;
   my $response  = $self->bucket->get_key($attach_id);
   if (!$response) {
     warn "Failed to retrieve attachment $attach_id from S3: "
@@ -75,7 +82,7 @@ sub get_data {
 
 sub remove_data {
   my ($self) = @_;
-  my $attach_id = $self->attachment->id;
+  my $attach_id = $self->attach_id;
   $self->bucket->delete_key($attach_id)
     or warn "Failed to remove attachment $attach_id from S3: "
     . $self->bucket->errstr . "\n";
@@ -84,7 +91,7 @@ sub remove_data {
 
 sub data_exists {
   my ($self) = @_;
-  return !!$self->bucket->head_key($self->attachment->id);
+  return !!$self->bucket->head_key($self->attach_id);
 }
 
 1;
index dcb5e020ecb5f2a611bea281fb4f0ff42dc6e221..baa887677de074dec7273fa40052bc7e06557013 100644 (file)
@@ -384,7 +384,7 @@ sub process_revision_change {
   );
   INFO($log_message);
 
-# change to the phabricator user, which returns a guard that restores the previous user.
+  # change to the phabricator user, which returns a guard that restores the previous user.
   my $restore_prev_user = set_phab_user();
   my $bug               = $revision->bug;
 
@@ -460,7 +460,7 @@ sub process_revision_change {
 
   INFO('Checking for revision attachment');
   my $rev_attachment = create_revision_attachment($bug, $revision, $timestamp,
-    $revision->author->bugzilla_user);
+  $revision->author->bugzilla_user);
   INFO('Attachment ' . $rev_attachment->id . ' created or already exists.');
 
   # ATTACHMENT OBSOLETES
@@ -630,7 +630,6 @@ sub process_new_user {
     f7 => 'reporter',
     o7 => 'equals',
     v7 => $bug_user->login,
-
     f9 => 'CP',
 
     # The bug needs to be private