From 83e3b2ef9ed0c5d6d40ad095d87b59e0ccdeb46e Mon Sep 17 00:00:00 2001 From: Jeff Baskin Date: Fri, 16 Dec 2022 08:22:36 -0500 Subject: [PATCH] Removed duplicate ids. --- src/morethantext/mod.rs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/morethantext/mod.rs b/src/morethantext/mod.rs index c499d33..28b8a8c 100644 --- a/src/morethantext/mod.rs +++ b/src/morethantext/mod.rs @@ -67,9 +67,15 @@ impl MoreThanText { } async fn add_entry(&self, entry: CacheEntry) -> String { - let id: String = thread_rng().sample_iter(&Alphanumeric).take(32).collect(); - let file = Path::new(&self.dir).join(&id); - write(file, entry.to_bytes()).await.unwrap(); + let mut id: String = "".to_string(); + let mut dup = true; + while dup { + id = thread_rng().sample_iter(&Alphanumeric).take(32).collect(); + dup = Path::new(&self.dir).join(&id).as_path().exists().await; + } + write(Path::new(&self.dir).join(&id), entry.to_bytes()) + .await + .unwrap(); let mut cache = self.cache.lock().await; cache.insert(id.clone(), entry); return id; @@ -160,12 +166,6 @@ mod cache { use super::*; use setup::MTT; - #[async_std::test] - async fn ids_are_random() { - let mtt = MTT::new().await; - mtt.db.new_id().await; - } - #[async_std::test] async fn entry_ids_are_random() { let mtt = MTT::new().await;