Compare commits

...

2 Commits

Author SHA1 Message Date
Jeff Baskin 83e3b2ef9e Removed duplicate ids. 2022-12-16 08:22:36 -05:00
Jeff Baskin ab30604033 Writes out contents of the cache. 2022-12-15 12:20:40 -05:00
1 changed files with 10 additions and 4 deletions

View File

@ -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;
@ -161,7 +167,7 @@ mod cache {
use setup::MTT;
#[async_std::test]
async fn ids_are_random() {
async fn entry_ids_are_random() {
let mtt = MTT::new().await;
let data1 = CacheEntry::Raw("one".to_string());
let data2 = CacheEntry::Raw("two".to_string());