From cc770cdf9eb5e8174cab85ec3be143ed4158206f Mon Sep 17 00:00:00 2001 From: hjp Date: Sat, 29 Sep 2012 10:44:10 +0000 Subject: [PATCH] Read all checksums from the last session and store them in a hash. This should speed up retrieving checksums considerably. --- lib/Simba/CA.pm | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/lib/Simba/CA.pm b/lib/Simba/CA.pm index 6db94cc..2207277 100644 --- a/lib/Simba/CA.pm +++ b/lib/Simba/CA.pm @@ -443,14 +443,7 @@ sub db_record_version { $self->{times}{db_record_version_insert_files} += $t2 - $t1; if ($f->{t} eq 'f' && !defined($f->{checksum})) { # this must be a link to the previous version - my $db_pv = $self->{dbh}->selectall_arrayref( - "select * from versions2 v, instances i - where file=? and session=? and v.id = i.version", - { Slice => {} }, - $db_f->[0]{id}, - $self->{last_backup_id} - ); - $f->{checksum} = $db_pv->[0]{checksum}; + $f->{checksum} = $self->get_checksum($db_f->[0]{id}); } my $t2a = gettimeofday(); $self->{times}{db_record_version_versions2_get_checksum} += $t2a - $t2; @@ -525,6 +518,23 @@ sub db_record_version { $self->{times}{db_record_version} += $t4 - $t0; } +sub get_checksum { + my ($self, $file) = @_; + if ($self->{caches}{file_checksums}{$self->{last_backup_id}}) { + return $self->{caches}{file_checksums}{$self->{last_backup_id}}{$file}; + } else { + $self->{caches}{file_checksums}{$self->{last_backup_id}} = my $file_checksums = {}; + my $sth = $self->{dbh}->prepare( + "select file, checksum from versions2 v, instances i + where session=? and v.id = i.version"); + $sth->execute($self->{last_backup_id}); + while (my ($file, $checksum) = $sth->fetchrow_array) { + $file_checksums->{$file} = $checksum; + } + + return $file_checksums->{$file}; + } +} sub flush_insert_instances { my ($self) = @_;