Skip to content

Commit

Permalink
For #220 use -M comparison as more efficient.
Browse files Browse the repository at this point in the history
  • Loading branch information
drn05r committed Apr 29, 2022
1 parent d940ee2 commit 7d658dd
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 20 deletions.
4 changes: 2 additions & 2 deletions lib/cfg.d/template_core.pl
Expand Up @@ -39,11 +39,11 @@
$head->appendChild( $repo->xml->create_element( "link",
rel => "stylesheet",
type => "text/css",
href => $repo->current_url( path => "static", "style/auto-".EPrints->human_version.".css" ) . "?".$repo->auto_last_modified( 'style' ),
href => $repo->current_url( path => "static", "style/auto-".EPrints->human_version.".css" ) . "?".$repo->auto_most_recent( 'style' ),
) );
$head->appendChild( $repo->xml->create_text_node( "\n " ) );
$head->appendChild( $repo->make_javascript( undef,
src => $repo->current_url( path => "static", "javascript/auto-".EPrints->human_version.".js" ) . "?".$repo->auto_last_modified( 'javascript' ),
src => $repo->current_url( path => "static", "javascript/auto-".EPrints->human_version.".js" ) . "?".$repo->auto_most_recent( 'javascript' ),
) );
$head->appendChild( $repo->xml->create_text_node( "\n " ) );

Expand Down
16 changes: 8 additions & 8 deletions perl_lib/EPrints/Repository.pm
Expand Up @@ -6018,14 +6018,14 @@ style or javascript.
=cut
######################################################################

sub auto_last_modified
sub auto_most_recent
{

my ( $self, $type ) = @_;

my $style_path = "/static/$type/auto/";

my $last_modified_time = EPrints::Utils::last_modified_time_in_dir( $self->config( "lib_path" ).$style_path );
my $most_recent_time = EPrints::Utils::most_recent_time_in_dir( $self->config( "lib_path" ).$style_path );

my $flavour = $self->config( "flavour" );
my $lib_order = $self->config('flavours')->{$flavour};
Expand All @@ -6036,14 +6036,14 @@ sub auto_last_modified
{
next;
}
my $new_last_modified_time = EPrints::Utils::last_modified_time_in_dir( $dir );
$last_modified_time = ( $new_last_modified_time > $last_modified_time ) ? $new_last_modified_time : $last_modified_time;
my $new_most_recent_time = EPrints::Utils::most_recent_time_in_dir( $dir );
$most_recent_time = $new_most_recent_time if $new_most_recent_time < $most_recent_time;
}

my $new_last_modified_time = EPrints::Utils::last_modified_time_in_dir( $self->config( "config_path" ).$style_path );
$last_modified_time = ( $new_last_modified_time > $last_modified_time ) ? $new_last_modified_time : $last_modified_time;
return $last_modified_time;
my $new_most_recent_time = EPrints::Utils::most_recent_time_in_dir( $self->config( "config_path" ).$style_path );
$most_recent_time = $new_most_recent_time if $new_most_recent_time < $most_recent_time;

return $most_recent_time;
}

1;
Expand Down
18 changes: 8 additions & 10 deletions perl_lib/EPrints/Utils.pm
Expand Up @@ -1541,23 +1541,21 @@ sub validate_email
}

# EPrints::Utils::last_modified_time_in_dir ( $dir );
# Get seconds since start of last epoch for last modified file in a particular directory (non-recursive).
sub last_modified_time_in_dir
# Get decimal value in days relative to the start time of the process for file most recently modified (non-recursive).
sub most_recent_time_in_dir
{
my ( $dir ) = @_;

opendir my $dh, $dir or return 0;
my $last_modified_time = 0;
opendir my $dh, $dir or return 1000000000; # I.e. an impossibly large number of days.
my $most_recent_modified_time = 1000000000; # Initially an impossibly large number of days.
while ( defined( my $file = readdir($dh) ) ) {
my $path = File::Spec->catfile( $dir, $file );
next if -d $path; # skip directories
my $modified_time = (stat($path))[9];
if ( $modified_time > $last_modified_time )
my $modified_time = -M "$dir/$file";
if ( $modified_time < $most_recent_modified_time )
{
$last_modified_time = $modified_time;
$most_recent_modified_time = $modified_time;
}
}
return $last_modified_time;
return $most_recent_modified_time;
}

1;
Expand Down

1 comment on commit 7d658dd

@jesusbagpuss
Copy link
Contributor

@jesusbagpuss jesusbagpuss commented on 7d658dd Apr 29, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NB Just some ponderings - not criticism of the above - you were too quick with a commit! :)

It feels like there might be something different to be done with EPrints::Update::Static::update_auto off the back of this (which is part of the EPrints::Apache::Rewrite handling of requests for auto-x files)?
Could/should the timestamps be cached in $repo->{auto_js_timestamp} (or similar) - like the caching of phrase file timestamps?

With the above, I think that generating a static page will check the file times, and serving a request for the auto- file will also check the file times.
One or other of these is probably unnecessary? (I think checking it at the request side of things is best - and then caching it into $repo->{auto_css_timestamp}).

If you're running a generate_abstracts, does the complete template (including timestamped css links) get cached once, and re-used, or would the above checks be conducted for every abstract generated?

Should we also look at including integrity checks for these files?

Please sign in to comment.