Update deps.

This commit is contained in:
Syfaro 2019-12-13 03:22:37 -06:00
parent 2c5836109c
commit ba0aca1c80
3 changed files with 675 additions and 524 deletions

1153
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -5,11 +5,12 @@ authors = ["Syfaro <syfaro@huefox.com>"]
edition = "2018" edition = "2018"
[dependencies] [dependencies]
reqwest = "^0.9" reqwest = "0.9"
postgres = {version = "^0.15", features = ["with-chrono"]} postgres = { version = "0.17.0-alpha.2", features = ["with-chrono-0_4"] }
r2d2_postgres = "^0.14" tokio-postgres = { version = "0.5.0-alpha.2" }
r2d2 = "^0.8" r2d2_postgres = " 0.16.0-alpha.2"
chrono = "^0.4" r2d2 = "0.8"
chrono = "0.4"
[dependencies.furaffinity-rs] [dependencies.furaffinity-rs]
git = "https://git.huefox.com/syfaro/furaffinity-rs" git = "https://git.huefox.com/syfaro/furaffinity-rs"

View File

@ -1,6 +1,7 @@
type Client = r2d2::PooledConnection<r2d2_postgres::PostgresConnectionManager>; type Client =
r2d2::PooledConnection<r2d2_postgres::PostgresConnectionManager<tokio_postgres::tls::NoTls>>;
fn lookup_tag(client: &Client, tag: &str) -> i32 { fn lookup_tag(client: &mut Client, tag: &str) -> i32 {
if let Some(row) = client if let Some(row) = client
.query("SELECT id FROM tag WHERE name = $1", &[&tag]) .query("SELECT id FROM tag WHERE name = $1", &[&tag])
.unwrap() .unwrap()
@ -19,7 +20,7 @@ fn lookup_tag(client: &Client, tag: &str) -> i32 {
.get("id") .get("id")
} }
fn lookup_artist(client: &Client, artist: &str) -> i32 { fn lookup_artist(client: &mut Client, artist: &str) -> i32 {
if let Some(row) = client if let Some(row) = client
.query("SELECT id FROM artist WHERE name = $1", &[&artist]) .query("SELECT id FROM artist WHERE name = $1", &[&artist])
.unwrap() .unwrap()
@ -41,7 +42,7 @@ fn lookup_artist(client: &Client, artist: &str) -> i32 {
.get("id") .get("id")
} }
fn has_submission(client: &Client, id: i32) -> bool { fn has_submission(client: &mut Client, id: i32) -> bool {
client client
.query("SELECT id FROM submission WHERE id = $1", &[&id]) .query("SELECT id FROM submission WHERE id = $1", &[&id])
.expect("unable to run query") .expect("unable to run query")
@ -50,7 +51,7 @@ fn has_submission(client: &Client, id: i32) -> bool {
.is_some() .is_some()
} }
fn ids_to_check(client: &Client, max: i32) -> Vec<i32> { fn ids_to_check(client: &mut Client, max: i32) -> Vec<i32> {
let min = max - 100; let min = max - 100;
let rows = client.query("SELECT sid FROM generate_series(LEAST($1::int, (SELECT MIN(id) FROM SUBMISSION)), $2::int) sid WHERE sid NOT IN (SELECT id FROM submission where id = sid)", &[&min, &max]).unwrap(); let rows = client.query("SELECT sid FROM generate_series(LEAST($1::int, (SELECT MIN(id) FROM SUBMISSION)), $2::int) sid WHERE sid NOT IN (SELECT id FROM submission where id = sid)", &[&min, &max]).unwrap();
@ -59,14 +60,14 @@ fn ids_to_check(client: &Client, max: i32) -> Vec<i32> {
} }
fn insert_submission( fn insert_submission(
client: &Client, mut client: &mut Client,
sub: &furaffinity_rs::Submission, sub: &furaffinity_rs::Submission,
) -> Result<(), postgres::Error> { ) -> Result<(), postgres::Error> {
let artist_id = lookup_artist(&client, &sub.artist); let artist_id = lookup_artist(&mut client, &sub.artist);
let tag_ids: Vec<i32> = sub let tag_ids: Vec<i32> = sub
.tags .tags
.iter() .iter()
.map(|tag| lookup_tag(&client, &tag)) .map(|tag| lookup_tag(&mut client, &tag))
.collect(); .collect();
let hash = sub.hash.clone(); let hash = sub.hash.clone();
@ -84,13 +85,13 @@ fn insert_submission(
"INSERT INTO tag_to_post (tag_id, post_id) VALUES ($1, $2) ON CONFLICT DO NOTHING", "INSERT INTO tag_to_post (tag_id, post_id) VALUES ($1, $2) ON CONFLICT DO NOTHING",
)?; )?;
for tag_id in tag_ids { for tag_id in tag_ids {
stmt.execute(&[&tag_id, &sub.id])?; client.execute(&stmt, &[&tag_id, &sub.id])?;
} }
Ok(()) Ok(())
} }
fn insert_null_submission(client: &Client, id: i32) -> Result<u64, postgres::Error> { fn insert_null_submission(client: &mut Client, id: i32) -> Result<u64, postgres::Error> {
client.execute("INSERT INTO SUBMISSION (id) VALUES ($1)", &[&id]) client.execute("INSERT INTO SUBMISSION (id) VALUES ($1)", &[&id])
} }
@ -107,18 +108,18 @@ fn main() {
let dsn = std::env::var("POSTGRES_DSN").expect("missing postgres dsn"); let dsn = std::env::var("POSTGRES_DSN").expect("missing postgres dsn");
let manager = let manager =
r2d2_postgres::PostgresConnectionManager::new(dsn, r2d2_postgres::TlsMode::None).unwrap(); r2d2_postgres::PostgresConnectionManager::new(dsn.parse().unwrap(), postgres::NoTls);
let pool = r2d2::Pool::new(manager).unwrap(); let pool = r2d2::Pool::new(manager).unwrap();
'main: loop { 'main: loop {
let client = pool.get().unwrap(); let mut client = pool.get().unwrap();
let latest_id = fa.latest_id().expect("unable to get latest id"); let latest_id = fa.latest_id().expect("unable to get latest id");
for id in ids_to_check(&client, latest_id) { for id in ids_to_check(&mut client, latest_id) {
'attempt: for attempt in 0..3 { 'attempt: for attempt in 0..3 {
if !has_submission(&client, id) { if !has_submission(&mut client, id) {
println!("loading submission {}", id); println!("loading submission {}", id);
let sub = match fa.get_submission(id) { let sub = match fa.get_submission(id) {
@ -139,7 +140,7 @@ fn main() {
Some(sub) => sub, Some(sub) => sub,
None => { None => {
println!("did not exist"); println!("did not exist");
insert_null_submission(&client, id).unwrap(); insert_null_submission(&mut client, id).unwrap();
break 'attempt; break 'attempt;
} }
}; };
@ -149,10 +150,10 @@ fn main() {
Err(e) => { Err(e) => {
println!("unable to hash image: {:?}", e); println!("unable to hash image: {:?}", e);
sub sub
}, }
}; };
insert_submission(&client, &sub).unwrap(); insert_submission(&mut client, &sub).unwrap();
break 'attempt; break 'attempt;
} }