some speedups, I think this is most I can do without changing database
authordpavlin <dpavlin@8392b6e1-25fa-0310-8288-cc32f8e212ea>
Sat, 20 Aug 2005 14:13:58 +0000 (14:13 +0000)
committerdpavlin <dpavlin@8392b6e1-25fa-0310-8288-cc32f8e212ea>
Sat, 20 Aug 2005 14:13:58 +0000 (14:13 +0000)
git-svn-id: svn+ssh://llin/home/dpavlin/private/svn/BackupPC/trunk@48 8392b6e1-25fa-0310-8288-cc32f8e212ea

bin/BackupPC_updatedb

index d0f76f5..eb2e73c 100755 (executable)
@@ -1,8 +1,9 @@
 #!/usr/local/bin/perl -w
 
 use strict;
-use DBI;
 use lib "__INSTALLDIR__/lib";
+
+use DBI;
 use BackupPC::Lib;
 use BackupPC::View;
 use Data::Dumper;
@@ -10,6 +11,7 @@ use Getopt::Std;
 use Time::HiRes qw/time/;
 use File::Pid;
 use POSIX qw/strftime/;
+
 use constant BPC_FTYPE_DIR => 5;
 
 my $debug = 0;
@@ -280,10 +282,15 @@ sub getShareID() {
 
 sub found_in_db {
 
-       my ($shareID,undef,$name,$path,undef,$date,undef,$size) = @_;
+       my @data = @_;
+       shift @data;
+
+       my ($key, $shareID,undef,$name,$path,undef,$date,undef,$size) = @_;
+
+       return $beenThere->{$key} if (defined($beenThere->{$key}));
 
        $sth->{file_in_db} ||= $dbh->prepare(qq{
-               SELECT count(*) FROM files
+               SELECT 1 FROM files
                WHERE shareID = ? and
                        path = ? and 
                        name = ? and
@@ -293,8 +300,12 @@ sub found_in_db {
 
        my @param = ($shareID,$path,$name,$date,$size);
        $sth->{file_in_db}->execute(@param);
-       my ($rows) = $sth->{file_in_db}->fetchrow_array();
+       my $rows = $sth->{file_in_db}->rows;
        print STDERR "## found_in_db ",( $rows ? '+' : '-' ), join(" ",@param), "\n" if ($debug >= 3);
+
+       $beenThere->{$key}++;
+
+       $sth->{'insert_files'}->execute(@data) unless ($rows);
        return $rows;
 }
 
@@ -339,9 +350,9 @@ sub recurseDir($$$$$$$$) {
                        ));
 
 
-                       if (! $beenThere->{$key} && ! found_in_db(@data)) {
+                       if (! defined($beenThere->{$key}) && ! found_in_db($key, @data)) {
                                print STDERR "# key: $key [", $beenThere->{$key},"]" if ($debug >= 2);
-                               $sth->{'insert_files'}->execute(@data);
+
                                if ($filesInBackup->{$path_key}->{'type'} == BPC_FTYPE_DIR) {
                                        $new_dirs++;
                                        print STDERR " dir\n" if ($debug >= 2);
@@ -350,7 +361,6 @@ sub recurseDir($$$$$$$$) {
                                        print STDERR " file\n" if ($debug >= 2);
                                }
                        }
-                       $beenThere->{$key}++;
 
                        if ($filesInBackup->{$path_key}->{'type'} == BPC_FTYPE_DIR) {
                                $nr_dirs++;