pricecharts

track prices of consumer electronics
Log | Files | Refs | README

commit d2ac9667bffb2d99627935b0d1021541b85b477d
parent f2af491357d273f6b21c7a94297573a1bbe7131b
Author: Kyle Milz <kyle@getaddrinfo.net>
Date:   Mon,  3 Nov 2014 20:16:29 -0700

product_scraper: prepare queries outside of main loop

Diffstat:
Mproduct_scraper.pl | 18+++++++++++-------
1 file changed, 11 insertions(+), 7 deletions(-)

diff --git a/product_scraper.pl b/product_scraper.pl @@ -42,6 +42,14 @@ $email .= "------------ ------- ----- --- ----\n"; my $product_sth = $dbh->prepare("select * from products where part_num = ?"); +my $qry = "insert into products(part_num, manufacturer, description, type, " . + "first_seen, last_seen, last_scraped) values (?, ?, ?, ?, ?, ?, ?)"; +my $insert_sth = $dbh->prepare($qry); + +# also update description, manufacturer? +$qry = "update products set last_seen = ? where part_num = ?"; +my $update_sth = $dbh->prepare($qry); + my @new = (); for (keys %product_map) { @@ -106,17 +114,13 @@ for (keys %product_map) { $product_sth->execute($part_num); if ($product_sth->fetchrow_arrayref()) { - $dbh->do("update products set last_seen = ? where part_num = ?", - undef, time, $part_num); - # also update description, manufacturer here? + $update_sth->execute(time, $part_num); vprint(" "); $old++; } else { - $dbh->do("insert into products(part_num, manufacturer, description," . - "type, first_seen, last_seen, last_scraped) " . - "values (?, ?, ?, ?, ?, ?, ?)", undef, - $part_num, $brand, $title, $_, time, time, 0); + $insert_sth->execute($part_num, $brand, $title, $_, + time, time, 0); push @new, ([$_, $brand, $title, $part_num]); vprint("+ "); $new++;