brown-bag bug: I was using MARC.pm wrong: now whole file will be loaded
authorDobrica Pavlinusic <dpavlin@rot13.org>
Sun, 1 Feb 2004 22:06:00 +0000 (22:06 +0000)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Sun, 1 Feb 2004 22:06:00 +0000 (22:06 +0000)
at start of indexing, changing memory usage to much more step-like, but
that enables real progress indicator and few seconds gain in indexing
speed.

git-svn-id: file:///home/dpavlin/private/svn/webpac/trunk@215 13eb9ef6-21d5-0310-b721-a9d68796d827

all2xml.pl
marc_sf.pm

index 1acbca1..c625e3f 100755 (executable)
@@ -798,14 +798,17 @@ print STDERR "using: $type...\n";
                                file=>$marc_file, format=>$format
                        }) || die "Can't open MARC file '$marc_file'";
 
-               my $i=0;        # record nr.
+               # read MARC file in memory
+               $marc->nextmarc(-1);
 
-               my $rec;
+               my $max_rec = $marc->marc_count();
 
-               while ($marc->nextmarc(1)) {
+               for(my $i=1; $i<=$max_rec; $i++) {
 
-                       # XXX
-                       fakeprogress($i++);
+                       progress($i,$max_rec);
+
+                       # store value for marc_sf.pm
+                       $main::cache->{marc_record} = $i;
 
                        my $swishpath = $database."#".$i;
 
@@ -817,6 +820,9 @@ print STDERR "using: $type...\n";
                                print "Document-Type: XML\n\n$xml\n";
                        }
                }
+
+               print STDERR "\n";
+
        } elsif ($type_base eq "feed") {
 
                $import2cp = Text::Iconv->new($config->{feed_codepage},$codepage);
index d21a508..0cae113 100644 (file)
@@ -10,7 +10,9 @@ sub marc_sf {
 
        my $i = shift @_ || 0;
 
-       my @out = $marc->getvalue({record=>$marc->marc_count(),field=>$f,subfield=>$s});
+       my $rec = $main::cache->{marc_record} || die '$cache->{marc_record} is undefined!';
+
+       my @out = $marc->getvalue({record=>$rec,field=>$f,subfield=>$s});
 
        return $out[$i] if (@out && $out[$i]);
 }