diff options
Diffstat (limited to 'src/main.rs')
| -rw-r--r-- | src/main.rs | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/src/main.rs b/src/main.rs index ff3e596..3811e4a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -251,16 +251,24 @@ fn update_images(db: &Connection, file: &str, auth: &mut Auth, img: DockerRef, e metrics::get().images_checked.with_label_values(&[registry]).inc(); - let _last_checked = match db.query_one(" + let query_result = { + let _timer = metrics::get().db_query_duration.start_timer(); + db.query_one(" SELECT last_checked FROM images WHERE registry = ?1 AND image = ?2 - ", (registry, image), |row| row.get::<_, chrono::DateTime<chrono::Utc>>(0)).optional() { + ", (registry, image), |row| row.get::<_, chrono::DateTime<chrono::Utc>>(0)).optional() + }; + + let _last_checked = match query_result { Ok(Some(x)) => x, Ok(None) => { let time = chrono::offset::Utc::now(); - db.execute(" - INSERT INTO images(registry, image, last_checked) VALUES (?1, ?2, ?3) - ", (registry, &image, time)).unwrap(); + { + let _timer = metrics::get().db_query_duration.start_timer(); + db.execute(" + INSERT INTO images(registry, image, last_checked) VALUES (?1, ?2, ?3) + ", (registry, &image, time)).unwrap(); + } time }, Err(_x) => return Err("Database Failure".to_string()), |
