/[couchdb]/scripts/reblog2couchdb.pl
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /scripts/reblog2couchdb.pl

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 6 by dpavlin, Tue Aug 5 16:22:43 2008 UTC revision 7 by dpavlin, Tue Aug 5 16:36:57 2008 UTC
# Line 25  my $sql = qq{ Line 25  my $sql = qq{
25          join feeds on items.feed_id = feeds.id          join feeds on items.feed_id = feeds.id
26          where items.id > ?          where items.id > ?
27          order by items.id asc          order by items.id asc
28          limit 1000          limit 5000
29  };  };
30    
31    
# Line 44  print "status ",dump( $status->{data} ), Line 44  print "status ",dump( $status->{data} ),
44    
45  my $last_row = $status->{data}->{last_row_id} || 0;  my $last_row = $status->{data}->{last_row_id} || 0;
46    
47    sub commit_last_row {
48            warn "commit_last_row $last_row\n";
49            $status->{data}->{last_row_id} = $last_row;
50            $status->update;
51    }
52    
53  my $dbh = DBI->connect($dbi,"","") || die $DBI::errstr;  my $dbh = DBI->connect($dbi,"","") || die $DBI::errstr;
54    
55  print "Fetching items from $dbi id > $last_row\n";  print "Fetching items from $dbi id > $last_row\n";
# Line 80  while (my $row = $sth->fetchrow_hashref( Line 86  while (my $row = $sth->fetchrow_hashref(
86                  $doc->retrieve;                  $doc->retrieve;
87                  row2doc( $row, $doc )->update;                  row2doc( $row, $doc )->update;
88  #               eval { $doc->update };  #               eval { $doc->update };
89                  warn ( $@ ? "ERROR $_id $@" : "updated $_id" ), $/;                  warn $@ ? "ERROR $_id $@\n" : "updated $_id\n";
90          } else {          } else {
91                  warn "created ",dump( $row ),$/;                  warn "created $_id\n";
92          }          }
93    
94            $last_row = $row->{id};
95          $count++;          $count++;
96          if ( $count++ % 100 == 0 ) {    # checkpoint every 100 records  
97                  $status->{data}->{last_row_id} = $row->{id};          commit_last_row if $count % 100 == 0    # checkpoint every 100 records
                 $status->update;  
         }  
98  }  }
99    
100  # end checkpoint  commit_last_row;
 $status->{data}->{last_row_id} = $last_row;  
 $status->update;  
101    
102  __END__  __END__
103    

Legend:
Removed from v.6  
changed lines
  Added in v.7

  ViewVC Help
Powered by ViewVC 1.1.26