From f5dd11f8b3eb9b3285fa8c58d611e2dd46d35fda Mon Sep 17 00:00:00 2001 From: Jesper Jensen Date: Mon, 9 Feb 2026 17:37:56 +0100 Subject: Remove timestamp from tags These were never needed --- src/db.rs | 54 +++++++++++++++++++++++++++++------------------------- 1 file changed, 29 insertions(+), 25 deletions(-) (limited to 'src/db.rs') diff --git a/src/db.rs b/src/db.rs index 469a279..26ea78a 100644 --- a/src/db.rs +++ b/src/db.rs @@ -17,10 +17,10 @@ pub trait Db { fn get_expired_images(&self, now: &DateTime) -> Vec; fn get_tags_sorted(&self, image_id: i64) -> Vec; fn delete_tag(&self, image_id: i64, tag: &str); - fn insert_tag(&self, image_id: i64, tag: &str, fetched_at: &DateTime); + fn insert_tag(&self, image_id: i64, tag: &str); fn set_expires_at(&self, image_id: i64, expires_at: &DateTime); fn get_tag_digest(&self, image_id: i64, tag: &str) -> Option; - fn update_tag_digest(&self, image_id: i64, tag: &str, digest: &str, fetched_at: &DateTime); + fn update_tag_digest(&self, image_id: i64, tag: &str, digest: &str); } pub struct SqliteDb { @@ -113,6 +113,11 @@ impl SqliteDb { conn.execute("INSERT INTO migrations(id) VALUES (?1)", (7, )).unwrap(); } + if newest_migration < 8 { + conn.execute("ALTER TABLE tags DROP COLUMN fetched_at", ()).unwrap(); + conn.execute("INSERT INTO migrations(id) VALUES (?1)", (8, )).unwrap(); + } + return SqliteDb { conn }; } } @@ -174,10 +179,10 @@ impl Db for SqliteDb { (image_id, tag)).unwrap(); } - fn insert_tag(&self, image_id: i64, tag: &str, fetched_at: &DateTime) { + fn insert_tag(&self, image_id: i64, tag: &str) { let _timer = crate::metrics::get().db_query_duration.start_timer(); - self.conn.execute("INSERT INTO tags(image_id, tag, fetched_at) VALUES (?1, ?2, ?3)", - (image_id, tag, fetched_at)).unwrap(); + self.conn.execute("INSERT INTO tags(image_id, tag) VALUES (?1, ?2)", + (image_id, tag)).unwrap(); } fn set_expires_at(&self, image_id: i64, expires_at: &DateTime) { @@ -192,10 +197,10 @@ impl Db for SqliteDb { ", (image_id, tag), |row| row.get::<_, String>(0)).optional().unwrap(); } - fn update_tag_digest(&self, image_id: i64, tag: &str, digest: &str, fetched_at: &DateTime) { + fn update_tag_digest(&self, image_id: i64, tag: &str, digest: &str) { let _timer = crate::metrics::get().db_query_duration.start_timer(); - self.conn.execute("UPDATE tags SET digest = ?1, fetched_at = ?2 WHERE image_id = ?3 AND tag = ?4", - (digest, fetched_at, image_id, tag)).unwrap(); + self.conn.execute("UPDATE tags SET digest = ?1 WHERE image_id = ?2 AND tag = ?3", + (digest, image_id, tag)).unwrap(); } } @@ -203,7 +208,7 @@ impl Db for SqliteDb { pub struct StubDb { next_id: std::cell::RefCell, images: std::cell::RefCell>, - tags: std::cell::RefCell, DateTime)>>, + tags: std::cell::RefCell)>>, } #[cfg(test)] @@ -262,7 +267,7 @@ impl Db for StubDb { fn get_tags_sorted(&self, image_id: i64) -> Vec { let mut result = vec![]; - for (id, tag, _, _) in self.tags.borrow().iter() { + for (id, tag, _) in self.tags.borrow().iter() { if *id == image_id { result.push(tag.clone()); } @@ -272,11 +277,11 @@ impl Db for StubDb { } fn delete_tag(&self, image_id: i64, tag: &str) { - self.tags.borrow_mut().retain(|(id, t, _, _)| !(*id == image_id && t == tag)); + self.tags.borrow_mut().retain(|(id, t, _)| !(*id == image_id && t == tag)); } - fn insert_tag(&self, image_id: i64, tag: &str, fetched_at: &DateTime) { - self.tags.borrow_mut().push((image_id, tag.to_string(), None, fetched_at.clone())); + fn insert_tag(&self, image_id: i64, tag: &str) { + self.tags.borrow_mut().push((image_id, tag.to_string(), None)); } fn set_expires_at(&self, image_id: i64, expires_at: &DateTime) { @@ -289,7 +294,7 @@ impl Db for StubDb { } fn get_tag_digest(&self, image_id: i64, tag: &str) -> Option { - for (id, t, digest, _) in self.tags.borrow().iter() { + for (id, t, digest) in self.tags.borrow().iter() { if *id == image_id && t == tag { return digest.clone(); } @@ -297,11 +302,10 @@ impl Db for StubDb { return None; } - fn update_tag_digest(&self, image_id: i64, tag: &str, digest: &str, fetched_at: &DateTime) { - for (id, t, d, fa) in self.tags.borrow_mut().iter_mut() { + fn update_tag_digest(&self, image_id: i64, tag: &str, digest: &str) { + for (id, t, d) in self.tags.borrow_mut().iter_mut() { if *id == image_id && t == tag { *d = Some(digest.to_string()); - *fa = fetched_at.clone(); return; } } @@ -346,9 +350,9 @@ mod tests { let now = Utc.with_ymd_and_hms(2000, 1, 1, 0, 0, 0).unwrap(); let mut img = Image { id: 0, registry: "docker.io".into(), image: "nginx".into(), expires_at: now }; db.insert_image(&mut img); - db.insert_tag(img.id, "2.0", &now); - db.insert_tag(img.id, "1.0", &now); - db.insert_tag(img.id, "latest", &now); + db.insert_tag(img.id, "2.0"); + db.insert_tag(img.id, "1.0"); + db.insert_tag(img.id, "latest"); assert_eq!(db.get_tags_sorted(img.id), vec!["1.0", "2.0", "latest"]); } @@ -356,8 +360,8 @@ mod tests { let now = Utc.with_ymd_and_hms(2000, 1, 1, 0, 0, 0).unwrap(); let mut img = Image { id: 0, registry: "docker.io".into(), image: "nginx".into(), expires_at: now }; db.insert_image(&mut img); - db.insert_tag(img.id, "1.0", &now); - db.insert_tag(img.id, "2.0", &now); + db.insert_tag(img.id, "1.0"); + db.insert_tag(img.id, "2.0"); db.delete_tag(img.id, "1.0"); assert_eq!(db.get_tags_sorted(img.id), vec!["2.0"]); } @@ -375,7 +379,7 @@ mod tests { let now = Utc.with_ymd_and_hms(2000, 1, 1, 0, 0, 0).unwrap(); let mut img = Image { id: 0, registry: "docker.io".into(), image: "nginx".into(), expires_at: now }; db.insert_image(&mut img); - db.insert_tag(img.id, "1.0", &now); + db.insert_tag(img.id, "1.0"); assert_eq!(db.get_tag_digest(img.id, "1.0"), None); } @@ -383,8 +387,8 @@ mod tests { let now = Utc.with_ymd_and_hms(2000, 1, 1, 0, 0, 0).unwrap(); let mut img = Image { id: 0, registry: "docker.io".into(), image: "nginx".into(), expires_at: now }; db.insert_image(&mut img); - db.insert_tag(img.id, "1.0", &now); - db.update_tag_digest(img.id, "1.0", "sha256:abc", &now); + db.insert_tag(img.id, "1.0"); + db.update_tag_digest(img.id, "1.0", "sha256:abc"); assert_eq!(db.get_tag_digest(img.id, "1.0"), Some("sha256:abc".to_string())); } -- cgit v1.2.3