performance increases to the Gallery, bug #4103
This commit is contained in:
parent
fec49433c3
commit
f5aafd53e0
3 changed files with 107 additions and 49 deletions
|
|
@ -472,35 +472,16 @@ sub getTemplateVars {
|
|||
}
|
||||
}
|
||||
|
||||
# Add some things from Gallery
|
||||
my $galleryVar = $self->getGallery->getTemplateVars;
|
||||
for my $key ( qw{ url_listFilesForCurrentUser url_search } ) {
|
||||
$var->{ $key } = $galleryVar->{ $key };
|
||||
}
|
||||
|
||||
# More things from Gallery, but with different names
|
||||
for my $key ( qw{ title menuTitle url } ) {
|
||||
$var->{ "gallery_" . $key } = $galleryVar->{ $key };
|
||||
}
|
||||
|
||||
# Add some things from Album
|
||||
my $album = $self->getParent;
|
||||
my $albumVar = $album->getTemplateVars;
|
||||
for my $key ( qw{ title menuTitle url thumbnailUrl } ) {
|
||||
$var->{ "album_" . $key } = $albumVar->{ $key };
|
||||
}
|
||||
|
||||
# Add the search form
|
||||
$self->getGallery->appendTemplateVarsSearchForm( $var );
|
||||
|
||||
# Add a text-only synopsis
|
||||
$var->{ synopsis_textonly } = WebGUI::HTML::filter( $self->get('synopsis'), "all" );
|
||||
|
||||
# Figure out on what page of the album the gallery file belongs.
|
||||
my $album = $self->getParent;
|
||||
my $fileIdsInAlbum = $album->getFileIds;
|
||||
my $id = $self->getId;
|
||||
my $pageNumber =
|
||||
int (
|
||||
( first_index { $_ eq $self->getId } @{ $fileIdsInAlbum } ) # Get index of file in album
|
||||
( first_index { $_ eq $id } @{ $fileIdsInAlbum } ) # Get index of file in album
|
||||
/ $album->getParent->get( 'defaultFilesPerPage' ) # Divide by the number of files per page
|
||||
) + 1; # Round upwards
|
||||
|
||||
|
|
@ -773,6 +754,27 @@ sub view {
|
|||
|
||||
$self->appendTemplateVarsCommentForm( $var );
|
||||
|
||||
# Add the search form
|
||||
$self->getGallery->appendTemplateVarsSearchForm( $var );
|
||||
|
||||
# Add some things from Gallery
|
||||
my $galleryVar = $self->getGallery->getTemplateVars;
|
||||
for my $key ( qw{ url_listFilesForCurrentUser url_search } ) {
|
||||
$var->{ $key } = $galleryVar->{ $key };
|
||||
}
|
||||
|
||||
# More things from Gallery, but with different names
|
||||
for my $key ( qw{ title menuTitle url } ) {
|
||||
$var->{ "gallery_" . $key } = $galleryVar->{ $key };
|
||||
}
|
||||
|
||||
# Add some things from Album
|
||||
my $album = $self->getParent;
|
||||
my $albumVar = $album->getTemplateVars;
|
||||
for my $key ( qw{ title menuTitle url thumbnailUrl } ) {
|
||||
$var->{ "album_" . $key } = $albumVar->{ $key };
|
||||
}
|
||||
|
||||
# Keywords
|
||||
my $k = WebGUI::Keyword->new( $session );
|
||||
my $keywords = $k->getKeywordsForAsset( { asArrayRef => 1, asset => $self } );
|
||||
|
|
|
|||
|
|
@ -648,6 +648,8 @@ sub getAssetClassForFile {
|
|||
my $self = shift;
|
||||
my $filepath = shift;
|
||||
|
||||
$self->session->log->info( "Checking asset class for file '$filepath'" );
|
||||
|
||||
# Checks for Photo assets
|
||||
if ( $filepath =~ /\.(jpe?g|gif|png)$/i ) {
|
||||
return "WebGUI::Asset::File::GalleryFile::Photo";
|
||||
|
|
|
|||
|
|
@ -118,7 +118,9 @@ sub addArchive {
|
|||
|
||||
for my $filePath (@files) {
|
||||
my ($volume, $directory, $filename) = File::Spec->splitpath( $filePath );
|
||||
next unless $filename;
|
||||
next if $filename =~ m{^[.]};
|
||||
next if $filename =~ m{^thumb-};
|
||||
my $class = $gallery->getAssetClassForFile( $filePath );
|
||||
next unless $class; # class is undef for those files the Gallery can't handle
|
||||
|
||||
|
|
@ -194,8 +196,10 @@ sub appendTemplateVarsFileLoop {
|
|||
my $session = $self->session;
|
||||
|
||||
for my $assetId (@$assetIds) {
|
||||
push @{$var->{file_loop}},
|
||||
WebGUI::Asset->newByDynamicClass($session, $assetId)->getTemplateVars;
|
||||
my $asset = WebGUI::Asset->newByDynamicClass($session, $assetId);
|
||||
# Set the parent
|
||||
$asset->{_parent} = $self;
|
||||
push @{$var->{file_loop}}, $asset->getTemplateVars;
|
||||
}
|
||||
|
||||
return $var;
|
||||
|
|
@ -332,6 +336,21 @@ sub canView {
|
|||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
=head2 DESTROY
|
||||
|
||||
Destroy the cached assets
|
||||
|
||||
=cut
|
||||
|
||||
sub DESTROY {
|
||||
my $self = shift;
|
||||
for my $asset ( delete $self->{ qw/ _nextAlbum _prevAlbum / } ) {
|
||||
$asset->DESTROY;
|
||||
}
|
||||
}
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
=head2 i18n ( session )
|
||||
|
||||
Get a WebGUI::International object for this class.
|
||||
|
|
@ -415,23 +434,31 @@ Gets an array reference of asset IDs for all the files in this album.
|
|||
|
||||
sub getFileIds {
|
||||
my $self = shift;
|
||||
my $gallery = $self->getParent;
|
||||
|
||||
# Deal with "pending" files.
|
||||
my %pendingRules;
|
||||
if ( $self->canEdit ) {
|
||||
$pendingRules{ statusToInclude } = [ 'pending', 'approved' ];
|
||||
if ( !$self->session->stow->get( 'fileIds-' . $self->getId ) ) {
|
||||
my $gallery = $self->getParent;
|
||||
|
||||
# Deal with "pending" files.
|
||||
my %pendingRules;
|
||||
if ( $self->canEdit ) {
|
||||
$pendingRules{ statusToInclude } = [ 'pending', 'approved' ];
|
||||
}
|
||||
else {
|
||||
$pendingRules{ statusToInclude } = [ 'pending', 'approved' ];
|
||||
$pendingRules{ whereClause } = q{
|
||||
(
|
||||
status = "approved" || ownerUserId = "} . $self->session->user->userId . q{"
|
||||
)
|
||||
};
|
||||
}
|
||||
|
||||
$self->session->stow->set(
|
||||
"fileIds-" . $self->getId,
|
||||
$self->getLineage( ['descendants'], { (%pendingRules) } ),
|
||||
);
|
||||
}
|
||||
else {
|
||||
$pendingRules{ statusToInclude } = [ 'pending', 'approved' ];
|
||||
$pendingRules{ whereClause } = q{
|
||||
(
|
||||
status = "approved" || ownerUserId = "} . $self->session->user->userId . q{"
|
||||
)
|
||||
};
|
||||
}
|
||||
|
||||
return $self->getLineage( ['descendants'], { (%pendingRules) } );
|
||||
|
||||
return $self->session->stow->get( "fileIds-" . $self->getId );
|
||||
}
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
|
@ -465,9 +492,11 @@ or undef if there is no next album.
|
|||
|
||||
sub getNextAlbum {
|
||||
my $self = shift;
|
||||
return $self->{_nextAlbum} if $self->{_nextAlbum};
|
||||
my $nextId = $self->getParent->getNextAlbumId( $self->getId );
|
||||
return undef unless $nextId;
|
||||
return WebGUI::Asset->newByDynamicClass( $self->session, $nextId );
|
||||
$self->{_nextAlbum } = WebGUI::Asset->newByDynamicClass( $self->session, $nextId );
|
||||
return $self->{_nextAlbum};
|
||||
}
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
|
@ -481,9 +510,11 @@ or undef if there is no previous album.
|
|||
|
||||
sub getPreviousAlbum {
|
||||
my $self = shift;
|
||||
return $self->{_previousAlbum} if $self->{_previousAlbum};
|
||||
my $previousId = $self->getParent->getPreviousAlbumId( $self->getId );
|
||||
return undef unless $previousId;
|
||||
return WebGUI::Asset->newByDynamicClass( $self->session, $previousId );
|
||||
$self->{_previousAlbum} = WebGUI::Asset->newByDynamicClass( $self->session, $previousId );
|
||||
return $self->{_previousAlbum};
|
||||
}
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
|
@ -717,6 +748,30 @@ sub processPropertiesFromFormPost {
|
|||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
=head2 sendChunkedContent ( callback )
|
||||
|
||||
Send chunked content to the user. Will send the head of the style template,
|
||||
run the C<callback> to get the body content, then send the footer of the style
|
||||
template.
|
||||
|
||||
=cut
|
||||
|
||||
sub sendChunkedContent {
|
||||
my $self = shift;
|
||||
my $callback = shift;
|
||||
|
||||
$self->session->http->setLastModified($self->getContentLastModified);
|
||||
$self->session->http->sendHeader;
|
||||
my $style = $self->processStyle("~~~");
|
||||
my ($head, $foot) = split("~~~",$style);
|
||||
$self->session->output->print($head, 1);
|
||||
$self->session->output->print( $callback->() );
|
||||
$self->session->output->print($foot, 1);
|
||||
return "chunked";
|
||||
}
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
=head2 view ( )
|
||||
|
||||
method called by the www_view method. Returns a processed template
|
||||
|
|
@ -1264,9 +1319,9 @@ a javascript application in the template.
|
|||
sub www_slideshow {
|
||||
my $self = shift;
|
||||
|
||||
return $self->session->privilege->insufficient unless $self->canView;
|
||||
|
||||
return $self->processStyle( $self->view_slideshow );
|
||||
my $check = $self->checkView;
|
||||
return $check if (defined $check);
|
||||
return $self->sendChunkedContent( sub { $self->view_slideshow } );
|
||||
}
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
|
@ -1278,11 +1333,10 @@ Show the thumbnails for the album.
|
|||
=cut
|
||||
|
||||
sub www_thumbnails {
|
||||
my $self = shift;
|
||||
|
||||
return $self->session->privilege->insufficient unless $self->canView;
|
||||
|
||||
return $self->processStyle( $self->view_thumbnails );
|
||||
my $self = shift;
|
||||
my $check = $self->checkView;
|
||||
return $check if (defined $check);
|
||||
return $self->sendChunkedContent( sub { $self->view_thumbnails } );
|
||||
}
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue