[Rt-commit] rt branch, 4.4/external-storage, updated. rt-4.2.11-62-ge8431bc

Shawn Moore shawn at bestpractical.com
Fri May 22 18:37:43 EDT 2015


The branch, 4.4/external-storage has been updated
       via  e8431bc37e3a183437255a3f07bf5b0fe84054d7 (commit)
       via  b4a8c180c3c174a903e94f65d4b23a1dd288444d (commit)
       via  d9c6088c691d86218176e4a69551f82764e4c0af (commit)
       via  ced12a6b0152edc1442749f2368c580997085136 (commit)
       via  2053b60da85c2a4c8a1d110bb4ecea56311bffc1 (commit)
       via  25ee9a362f67d72094144ca7698997477e788254 (commit)
       via  56979bda6fb6d9d5b006866c2d4802a74ecf6507 (commit)
       via  4131abf4d8e9f35f5132c03d30ff0670de423fb6 (commit)
       via  84fb1658f044460cda4e79e8728f4ba924745f71 (commit)
       via  3838e23ee24c1f8436ee0e2c51a4adcc39fb0037 (commit)
      from  c244b30ca5c5b50dd08a1411376e1635004667a8 (commit)

Summary of changes:
 etc/RT_Config.pm.in                            | 15 +++++++++++++++
 lib/RT/Attachment.pm                           |  2 +-
 lib/RT/ExternalStorage/AmazonS3.pm             |  4 ++++
 lib/RT/ExternalStorage/Backend.pm              |  1 +
 lib/RT/ExternalStorage/Disk.pm                 |  4 ++++
 lib/RT/ExternalStorage/Dropbox.pm              |  4 ++++
 lib/RT/ObjectCustomFieldValue.pm               |  2 +-
 lib/RT/System.pm                               | 13 +++++++++++++
 share/html/Elements/EditCustomFieldBinary      | 12 +++++++++++-
 share/html/Elements/ShowCustomFieldBinary      |  9 ++++++++-
 share/html/Elements/ShowCustomFieldImage       |  5 ++++-
 share/html/Elements/ShowTransactionAttachments | 17 ++++++++++++-----
 share/html/Ticket/Elements/ShowAttachments     |  4 ++++
 share/html/Ticket/ShowEmailRecord.html         |  7 ++++---
 share/html/m/ticket/show                       |  4 ++++
 15 files changed, 90 insertions(+), 13 deletions(-)

- Log -----------------------------------------------------------------
commit 3838e23ee24c1f8436ee0e2c51a4adcc39fb0037
Author: Shawn M Moore <shawn at bestpractical.com>
Date:   Fri May 22 21:10:49 2015 +0000

    Add ExternalStorage->DirectLinkForObject API

diff --git a/lib/RT/ExternalStorage/AmazonS3.pm b/lib/RT/ExternalStorage/AmazonS3.pm
index 866d5f4..319f7d8 100644
--- a/lib/RT/ExternalStorage/AmazonS3.pm
+++ b/lib/RT/ExternalStorage/AmazonS3.pm
@@ -150,6 +150,10 @@ sub Store {
     return (1);
 }
 
+sub DirectLinkForObject {
+    return;
+}
+
 RT::Base->_ImportOverlays();
 
 1;
diff --git a/lib/RT/ExternalStorage/Backend.pm b/lib/RT/ExternalStorage/Backend.pm
index f69403d..866c22e 100644
--- a/lib/RT/ExternalStorage/Backend.pm
+++ b/lib/RT/ExternalStorage/Backend.pm
@@ -56,6 +56,7 @@ use Role::Basic;
 requires 'Init';
 requires 'Get';
 requires 'Store';
+requires 'DirectLinkForObject';
 
 sub new {
     my $class = shift;
diff --git a/lib/RT/ExternalStorage/Disk.pm b/lib/RT/ExternalStorage/Disk.pm
index 80eca68..f978b09 100644
--- a/lib/RT/ExternalStorage/Disk.pm
+++ b/lib/RT/ExternalStorage/Disk.pm
@@ -123,6 +123,10 @@ sub Store {
     return (1);
 }
 
+sub DirectLinkForObject {
+    return;
+}
+
 =head1 NAME
 
 RT::ExternalStorage::Disk - On-disk storage of attachments
diff --git a/lib/RT/ExternalStorage/Dropbox.pm b/lib/RT/ExternalStorage/Dropbox.pm
index 29c61c3..d00294f 100644
--- a/lib/RT/ExternalStorage/Dropbox.pm
+++ b/lib/RT/ExternalStorage/Dropbox.pm
@@ -119,6 +119,10 @@ sub Store {
     return (1);
 }
 
+sub DirectLinkForObject {
+    return;
+}
+
 =head1 NAME
 
 RT::ExternalStorage::Dropbox - Store files in the Dropbox cloud

commit 84fb1658f044460cda4e79e8728f4ba924745f71
Author: Shawn M Moore <shawn at bestpractical.com>
Date:   Fri May 22 21:46:17 2015 +0000

    Extract Digest directly to avoid loading the file from external storage

diff --git a/lib/RT/Attachment.pm b/lib/RT/Attachment.pm
index 3786d6f..c7995b7 100644
--- a/lib/RT/Attachment.pm
+++ b/lib/RT/Attachment.pm
@@ -1204,7 +1204,7 @@ sub ExternalStoreDigest {
     my $self = shift;
 
     return undef if $self->ContentEncoding ne 'external';
-    return $self->Content;
+    return $self->_Value('Content');
 }
 
 RT::Base->_ImportOverlays();
diff --git a/lib/RT/ObjectCustomFieldValue.pm b/lib/RT/ObjectCustomFieldValue.pm
index 4dc224d..b9e1430 100644
--- a/lib/RT/ObjectCustomFieldValue.pm
+++ b/lib/RT/ObjectCustomFieldValue.pm
@@ -751,7 +751,7 @@ sub ExternalStoreDigest {
     my $self = shift;
 
     return undef if $self->ContentEncoding ne 'external';
-    return $self->LargeContent;
+    return $self->_Value( 'LargeContent' );
 }
 
 RT::Base->_ImportOverlays();

commit 4131abf4d8e9f35f5132c03d30ff0670de423fb6
Author: Shawn M Moore <shawn at bestpractical.com>
Date:   Fri May 22 22:02:21 2015 +0000

    DirectLinkForObject -> DownloadURLFor

diff --git a/lib/RT/ExternalStorage/AmazonS3.pm b/lib/RT/ExternalStorage/AmazonS3.pm
index 319f7d8..1692463 100644
--- a/lib/RT/ExternalStorage/AmazonS3.pm
+++ b/lib/RT/ExternalStorage/AmazonS3.pm
@@ -150,7 +150,7 @@ sub Store {
     return (1);
 }
 
-sub DirectLinkForObject {
+sub DownloadURLFor {
     return;
 }
 
diff --git a/lib/RT/ExternalStorage/Backend.pm b/lib/RT/ExternalStorage/Backend.pm
index 866c22e..0f67996 100644
--- a/lib/RT/ExternalStorage/Backend.pm
+++ b/lib/RT/ExternalStorage/Backend.pm
@@ -56,7 +56,7 @@ use Role::Basic;
 requires 'Init';
 requires 'Get';
 requires 'Store';
-requires 'DirectLinkForObject';
+requires 'DownloadURLFor';
 
 sub new {
     my $class = shift;
diff --git a/lib/RT/ExternalStorage/Disk.pm b/lib/RT/ExternalStorage/Disk.pm
index f978b09..a5e9cfb 100644
--- a/lib/RT/ExternalStorage/Disk.pm
+++ b/lib/RT/ExternalStorage/Disk.pm
@@ -123,7 +123,7 @@ sub Store {
     return (1);
 }
 
-sub DirectLinkForObject {
+sub DownloadURLFor {
     return;
 }
 
diff --git a/lib/RT/ExternalStorage/Dropbox.pm b/lib/RT/ExternalStorage/Dropbox.pm
index d00294f..6291234 100644
--- a/lib/RT/ExternalStorage/Dropbox.pm
+++ b/lib/RT/ExternalStorage/Dropbox.pm
@@ -119,7 +119,7 @@ sub Store {
     return (1);
 }
 
-sub DirectLinkForObject {
+sub DownloadURLFor {
     return;
 }
 

commit 56979bda6fb6d9d5b006866c2d4802a74ecf6507
Author: Shawn M Moore <shawn at bestpractical.com>
Date:   Fri May 22 22:03:10 2015 +0000

    RT->System->ExternalStorageURLFor($Object)

diff --git a/lib/RT/System.pm b/lib/RT/System.pm
index 32c2866..1985789 100644
--- a/lib/RT/System.pm
+++ b/lib/RT/System.pm
@@ -335,6 +335,16 @@ sub ExternalStorage {
     return $self->{ExternalStorage};
 }
 
+sub ExternalStorageURLFor {
+    my $self = shift;
+    my $Object = shift;
+
+    # external storage not configured
+    return undef if !$self->ExternalStorage;
+
+    return $self->ExternalStorage->DownloadURLFor($Object);
+}
+
 RT::Base->_ImportOverlays();
 
 1;

commit 25ee9a362f67d72094144ca7698997477e788254
Author: Shawn M Moore <shawn at bestpractical.com>
Date:   Fri May 22 22:03:24 2015 +0000

    Add config to disable ExternalStorageDirectLink

diff --git a/etc/RT_Config.pm.in b/etc/RT_Config.pm.in
index 9935bf5..5ab68b6 100644
--- a/etc/RT_Config.pm.in
+++ b/etc/RT_Config.pm.in
@@ -2574,6 +2574,21 @@ the new ones that C<sbin/rt-externalize-attachments> hasn't seen yet.
 
 Set($ExternalStorageCutoffSize, 10*1024*1024);
 
+=item C<$ExternalStorageDirectLink>
+
+Certain ExternalStorage backends can serve files over HTTP (such as
+L<RT::ExternalStorage::AmazonS3>). For such backends, RT will link
+directly to those files in external storage. This cuts down download
+time and relieves resource pressure because RT's web server is no longer
+involved in retrieving and then immediately serving each attachment.
+
+If you prefer to have RT serve these files (perhaps to maintain an access
+log), you can set this option to false.
+
+=cut
+
+Set($ExternalStorageDirectLink, 1);
+
 =back
 
 =head1 Lifecycles
diff --git a/lib/RT/System.pm b/lib/RT/System.pm
index 1985789..547988f 100644
--- a/lib/RT/System.pm
+++ b/lib/RT/System.pm
@@ -342,6 +342,9 @@ sub ExternalStorageURLFor {
     # external storage not configured
     return undef if !$self->ExternalStorage;
 
+    # external storage direct links disabled
+    return undef if !RT->Config->Get('ExternalStorageDirectLink');
+
     return $self->ExternalStorage->DownloadURLFor($Object);
 }
 

commit 2053b60da85c2a4c8a1d110bb4ecea56311bffc1
Author: Shawn M Moore <shawn at bestpractical.com>
Date:   Fri May 22 22:12:32 2015 +0000

    Use direct external-storage URL for OCFVs where applicable

diff --git a/share/html/Elements/EditCustomFieldBinary b/share/html/Elements/EditCustomFieldBinary
index fc6ee3f..38f312e 100644
--- a/share/html/Elements/EditCustomFieldBinary
+++ b/share/html/Elements/EditCustomFieldBinary
@@ -47,7 +47,17 @@
 %# END BPS TAGGED BLOCK }}}
 % while ( $Values and my $value = $Values->Next ) {
 %# XXX - let user download the file(s) here?
-<input type="checkbox" name="<%$delete_name%>" class="checkbox CF-<%$CustomField->id%>-Edit" value="<% $value->Id %>" /><a href="<%RT->Config->Get('WebPath')%>/Download/CustomFieldValue/<% $value->Id %>/<% $value->Content |un %>"><% $value->Content %></a><br />
+<input type="checkbox" name="<%$delete_name%>" class="checkbox CF-<%$CustomField->id%>-Edit" value="<% $value->Id %>" />
+
+% if (my $url = RT->System->ExternalStorageURLFor($value)) {
+<a href="<%$url%>">
+% } else {
+<a href="<%RT->Config->Get('WebPath')%>/Download/CustomFieldValue/<% $value->Id %>/<% $value->Content |un %>">
+% }
+
+<% $value->Content %>
+</a>
+<br />
 % }
 % if ($MaxValues && $Values && $Values->Count >= $MaxValues ) {
 <div class="hints">
diff --git a/share/html/Elements/ShowCustomFieldBinary b/share/html/Elements/ShowCustomFieldBinary
index 544b54d..1a5672f 100644
--- a/share/html/Elements/ShowCustomFieldBinary
+++ b/share/html/Elements/ShowCustomFieldBinary
@@ -45,7 +45,14 @@
 %# those contributions and any derivatives thereof.
 %#
 %# END BPS TAGGED BLOCK }}}
-<a href="<%RT->Config->Get('WebPath')%>/Download/CustomFieldValue/<% $Object->Id %>/<% $Object->Content |un %>"><% $Object->Content %></a>
+% if (my $url = RT->System->ExternalStorageURLFor($Object)) {
+<a href="<%$url%>">
+% } else {
+<a href="<%RT->Config->Get('WebPath')%>/Download/CustomFieldValue/<% $Object->Id %>/<% $Object->Content |un %>">
+% }
+
+<% $Object->Content %>
+</a>
 <%ARGS>
 $Object => undef
 </%ARGS>
diff --git a/share/html/Elements/ShowCustomFieldImage b/share/html/Elements/ShowCustomFieldImage
index f5a1886..cc3a2aa 100644
--- a/share/html/Elements/ShowCustomFieldImage
+++ b/share/html/Elements/ShowCustomFieldImage
@@ -45,9 +45,12 @@
 %# those contributions and any derivatives thereof.
 %#
 %# END BPS TAGGED BLOCK }}}
-%    my $url = RT->Config->Get('WebPath') . "/Download/CustomFieldValue/".$Object->Id.'/'.$m->interp->apply_escapes($Object->Content, 'u');
 <a href="<% $url %>"><% $Object->Content %></a><br>
 <img type="<% $Object->ContentType %>" height="64" src="<% $url %>" align="middle" />
 <%ARGS>
 $Object
 </%ARGS>
+<%INIT>
+my $url = RT->System->ExternalStorageURLFor($Object)
+       || RT->Config->Get('WebPath') . "/Download/CustomFieldValue/".$Object->Id.'/'.$m->interp->apply_escapes($Object->Content, 'u');
+</%INIT>

commit ced12a6b0152edc1442749f2368c580997085136
Author: Shawn M Moore <shawn at bestpractical.com>
Date:   Fri May 22 22:27:38 2015 +0000

    Use direct external-storage URL for txn display

diff --git a/share/html/Elements/ShowTransactionAttachments b/share/html/Elements/ShowTransactionAttachments
index 7aeded6..dcc28f2 100644
--- a/share/html/Elements/ShowTransactionAttachments
+++ b/share/html/Elements/ShowTransactionAttachments
@@ -59,7 +59,12 @@ foreach my $message ( @{ $Attachments->{ $Parent || 0 } || [] } ) {
     if ( $message->ContentLength or $name ) {
 </%PERL>
 <div class="downloadattachment">
-<a href="<% $AttachmentPath %>/<% $Transaction->Id %>/<% $message->Id %>/<% $name | u%>"><&|/l&>Download</&> <% length $name ? $name : loc('(untitled)') %></a>\
+% if (my $url = RT->System->ExternalStorageURLFor($message)) {
+<a href="<% $url %>">
+% } else {
+<a href="<% $AttachmentPath %>/<% $Transaction->Id %>/<% $message->Id %>/<% $name | u%>">
+% }
+<&|/l&>Download</&> <% length $name ? $name : loc('(untitled)') %></a>\
 % if ( $DownloadableHeaders && ! length $name && $message->ContentType =~ /text/  ) {
  / <a href="<% $AttachmentPath %>/WithHeaders/<% $message->Id %>"><% loc('with headers') %></a>
 % }
@@ -275,11 +280,13 @@ my $render_attachment = sub {
 
         my $filename = length $name ? $name : loc('(untitled)');
         my $efilename = $m->interp->apply_escapes( $filename, 'h' );
+
+        my $url = RT->System->ExternalStorageURLFor($message)
+               || $AttachmentPath .'/'. $Transaction->Id .'/'. $message->Id .'/'
+                . $m->interp->apply_escapes( $filename, 'u', 'h' );
+
         $m->out(
-            qq{<img alt="$efilename" title="$efilename"}
-            . ' src="'. $AttachmentPath .'/'. $Transaction->Id .'/'. $message->Id .'/'
-                . $m->interp->apply_escapes( $filename, 'u', 'h' )
-            . '" />'
+            qq{<img alt="$efilename" title="$efilename" src="$url" />}
         );
     }
     elsif ( $message->ContentLength && $message->ContentLength > 0 ) {

commit d9c6088c691d86218176e4a69551f82764e4c0af
Author: Shawn M Moore <shawn at bestpractical.com>
Date:   Fri May 22 22:28:19 2015 +0000

    Use direct external-storage URL for attachment list

diff --git a/share/html/Ticket/Elements/ShowAttachments b/share/html/Ticket/Elements/ShowAttachments
index a567844..8116db5 100644
--- a/share/html/Ticket/Elements/ShowAttachments
+++ b/share/html/Ticket/Elements/ShowAttachments
@@ -58,7 +58,11 @@
 % foreach my $rev (@{$documents{$key}}) {
 % if ($rev->ContentLength) {
 <li><font size="-2">
+% if (my $url = RT->System->ExternalStorageURLFor($rev)) {
+<a href="<%$url%>">
+% } else {
 <a href="<%RT->Config->Get('WebPath')%>/Ticket/Attachment/<%$rev->TransactionId%>/<%$rev->Id%>/<%$rev->Filename | un %>">
+% }
 % my $desc = loc("[_1] ([_2]) by [_3]", $rev->CreatedAsString, $rev->FriendlyContentLength, $m->scomp('/Elements/ShowUser', User => $rev->CreatorObj));
 <% $desc |n%>
 </a>

commit b4a8c180c3c174a903e94f65d4b23a1dd288444d
Author: Shawn M Moore <shawn at bestpractical.com>
Date:   Fri May 22 22:33:42 2015 +0000

    Use direct external-storage URL for mobile UI attachments

diff --git a/share/html/m/ticket/show b/share/html/m/ticket/show
index ebf39ac..e0a8cf0 100644
--- a/share/html/m/ticket/show
+++ b/share/html/m/ticket/show
@@ -315,7 +315,11 @@ my $print_value = sub {
 % foreach my $rev (@{$documents{$key}}) {
 % if ($rev->ContentLength) {
 <li><font size="-2">
+% if (my $url = RT->System->ExternalStorageURLFor($rev)) {
+<a href="<%$url%>">
+% } else {
 <a href="<%RT->Config->Get('WebPath')%>/Ticket/Attachment/<%$rev->TransactionId%>/<%$rev->Id%>/<%$rev->Filename | un %>">
+% }
 <&|/l, $rev->CreatedAsString, $rev->FriendlyContentLength, $rev->CreatorObj->Name &>[_1] ([_2]) by [_3]</&>
 </a>
 </font></li>

commit e8431bc37e3a183437255a3f07bf5b0fe84054d7
Author: Shawn M Moore <shawn at bestpractical.com>
Date:   Fri May 22 22:37:32 2015 +0000

    Use direct external-storage URL for show email record

diff --git a/share/html/Ticket/ShowEmailRecord.html b/share/html/Ticket/ShowEmailRecord.html
index bdb2119..6742271 100644
--- a/share/html/Ticket/ShowEmailRecord.html
+++ b/share/html/Ticket/ShowEmailRecord.html
@@ -62,9 +62,10 @@ my $show_content = sub {
         $m->out( $content );
         return;
     }
-    my $href = RT->Config->Get('WebPath') .'/Ticket/Attachment/'
-        . $attach->TransactionId .'/'. $attach->id .'/'
-        . $m->interp->apply_escapes( $attach->Filename, 'u' );
+    my $href = RT->System->ExternalStorageURLFor($attach)
+            || RT->Config->Get('WebPath') .'/Ticket/Attachment/'
+             . $attach->TransactionId .'/'. $attach->id .'/'
+             . $m->interp->apply_escapes( $attach->Filename, 'u' );
     $m->out( '<a href="'. $href  .'">'. loc('download') .'</a>' );
 };
 

-----------------------------------------------------------------------


More information about the rt-commit mailing list