From 478c9a6720b45558636d97c7976bace3d5f99d0d Mon Sep 17 00:00:00 2001 From: Syfaro Date: Sat, 4 Jan 2020 16:37:29 -0600 Subject: [PATCH] Only insert cube if hash is some. --- src/main.rs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/main.rs b/src/main.rs index 86e9f42..d79e28d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -73,9 +73,15 @@ fn insert_submission( let hash = sub.hash.clone(); let url = sub.content.url(); - client.execute("INSERT INTO submission (id, artist_id, url, filename, hash, rating, posted_at, description, c) VALUES ($1, $2, $3, $4, decode($5, 'base64'), $6, $7, $8, CUBE(ARRAY[get_byte(decode($5, 'base64'), 0), get_byte(decode($5, 'base64'), 1), get_byte(decode($5, 'base64'), 2), get_byte(decode($5, 'base64'), 3), get_byte(decode($5, 'base64'), 4), get_byte(decode($5, 'base64'), 5), get_byte(decode($5, 'base64'), 6), get_byte(decode($5, 'base64'), 7)]::smallint[]))", &[ - &sub.id, &artist_id, &url, &sub.filename, &hash, &sub.rating.serialize(), &sub.posted_at, &sub.description, - ])?; + if hash.is_some() { + client.execute("INSERT INTO submission (id, artist_id, url, filename, hash, rating, posted_at, description, c) VALUES ($1, $2, $3, $4, decode($5, 'base64'), $6, $7, $8, CUBE(ARRAY[get_byte(decode($5, 'base64'), 0), get_byte(decode($5, 'base64'), 1), get_byte(decode($5, 'base64'), 2), get_byte(decode($5, 'base64'), 3), get_byte(decode($5, 'base64'), 4), get_byte(decode($5, 'base64'), 5), get_byte(decode($5, 'base64'), 6), get_byte(decode($5, 'base64'), 7)]::smallint[]))", &[ + &sub.id, &artist_id, &url, &sub.filename, &hash, &sub.rating.serialize(), &sub.posted_at, &sub.description, + ])?; + } else { + client.execute("INSERT INTO submission (id, artist_id, url, filename, hash, rating, posted_at, description) VALUES ($1, $2, $3, $4, decode($5, 'base64'), $6, $7, $8)", &[ + &sub.id, &artist_id, &url, &sub.filename, &hash, &sub.rating.serialize(), &sub.posted_at, &sub.description, + ])?; + } let stmt = client.prepare( "INSERT INTO tag_to_post (tag_id, post_id) VALUES ($1, $2) ON CONFLICT DO NOTHING",