Changeset 10833


Ignore:
Timestamp:
2005-11-02T17:31:10+13:00 (18 years ago)
Author:
jrm21
Message:

store the names of files we've already checked when looking for a cover
image, otherwise splitplug documents (eg email from the same file) causes
lots of file accesses to check if the cover image exists, which is slow

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gsdl/perllib/plugins/BasPlug.pm

    r10620 r10833  
    538538sub block_cover_image
    539539{
    540     my $self =shift (@_);
    541     my ($filename) = @_;
     540    my $self =shift;
     541    my $filename = shift;
     542
     543    if (exists $self->{'file_blocks'}->{$filename}) {
     544    # we've already checked if this file exists, so don't stat() again.
     545    # (eg for multi-sectioned files using SplitPlug)
     546    return;
     547    }
     548
    542549    if ($self->{'cover_image'}) {
    543550    my $coverfile = $filename;
     
    548555    if (-e $coverfile) {
    549556        $self->{'file_blocks'}->{$coverfile} = 1;
     557    } else {
     558        $self->{'file_blocks'}->{$coverfile} = 0;
    550559    }
    551560    }
     
    14471456
    14481457sub associate_cover_image {
    1449     my $self = shift(@_);
     1458    my $self = shift;
    14501459    my ($doc_obj, $filename) = @_;
    14511460
     1461    $filename =~ s/\.[^\\\/\.]+$/\.jpg/;
     1462    if (exists $self->{'covers_missing_cache'}->{$filename}) {
     1463    # don't stat() for existence eg for multiple document input files
     1464    # (eg SplitPlug)
     1465    return;
     1466    }
     1467
    14521468    my $top_section=$doc_obj->get_top_section();
    14531469
    1454     $filename =~ s/\.[^\\\/\.]+$/\.jpg/;
    14551470    if (-e $filename) {
    14561471    $doc_obj->associate_file($filename, "cover.jpg", "image/jpeg");
    14571472    $doc_obj->add_utf8_metadata($top_section, "hascover",  1);
    14581473    } else {
    1459     $filename =~ s/jpg$/JPG/;
    1460     if (-e $filename) {
    1461         $doc_obj->associate_file($filename, "cover.jpg", "image/jpeg");
     1474    my $upper_filename = $filename;
     1475    $upper_filename =~ s/jpg$/JPG/;
     1476    if (-e $upper_filename) {
     1477        $doc_obj->associate_file($upper_filename, "cover.jpg",
     1478                     "image/jpeg");
    14621479        $doc_obj->add_utf8_metadata($top_section, "hascover",  1);
    1463     }
    1464     }
     1480    } else {
     1481        # file doesn't exist, so record the fact that it's missing so
     1482        # we don't stat() again (stat is slow)
     1483        $self->{'covers_missing_cache'}->{$filename} = 1;
     1484    }
     1485    }
     1486
    14651487}
    14661488
Note: See TracChangeset for help on using the changeset viewer.