Skip to content

Commit 23531e7

Browse files
committed
Don't always use nested transactions when updating downloads
Allow using a Connection for what to update from to save partial progress.
1 parent 1be303b commit 23531e7

File tree

1 file changed

+4
-13
lines changed

1 file changed

+4
-13
lines changed

src/bin/update-downloads.rs

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,10 @@ fn main() {
2222
loop {
2323
let conn = postgres::Connection::connect(&env("DATABASE_URL")[..],
2424
&postgres::SslMode::None).unwrap();
25-
{
26-
let tx = conn.transaction().unwrap();
27-
update(&tx).unwrap();
28-
tx.set_commit();
29-
tx.finish().unwrap();
30-
}
25+
update(&conn).unwrap();
3126
drop(conn);
3227
if daemon {
33-
#[allow(deprecated)]
34-
fn do_sleep(sleep: Option<i64>) {
35-
std::thread::sleep(Duration::seconds(sleep.unwrap()));
36-
}
37-
do_sleep(sleep);
28+
std::thread::sleep(Duration::seconds(sleep.unwrap()));
3829
} else {
3930
break
4031
}
@@ -48,10 +39,10 @@ fn env(s: &str) -> String {
4839
}
4940
}
5041

51-
fn update(tx: &postgres::Transaction) -> postgres::Result<()> {
42+
fn update(conn: &postgres::GenericConnection) -> postgres::Result<()> {
5243
let mut max = 0;
5344
loop {
54-
let tx = try!(tx.transaction());
45+
let tx = try!(conn.transaction());
5546
{
5647
let stmt = try!(tx.prepare("SELECT * FROM version_downloads \
5748
WHERE processed = FALSE AND id > $1

0 commit comments

Comments
 (0)