Compare commits
No commits in common. "83e3b2ef9ed0c5d6d40ad095d87b59e0ccdeb46e" and "947adf6c1d1a48adc579dcc223f743f2aefda5c8" have entirely different histories.
83e3b2ef9e
...
947adf6c1d
@ -67,15 +67,9 @@ impl MoreThanText {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async fn add_entry(&self, entry: CacheEntry) -> String {
|
async fn add_entry(&self, entry: CacheEntry) -> String {
|
||||||
let mut id: String = "".to_string();
|
let id: String = thread_rng().sample_iter(&Alphanumeric).take(32).collect();
|
||||||
let mut dup = true;
|
let file = Path::new(&self.dir).join(&id);
|
||||||
while dup {
|
write(file, entry.to_bytes()).await.unwrap();
|
||||||
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;
|
let mut cache = self.cache.lock().await;
|
||||||
cache.insert(id.clone(), entry);
|
cache.insert(id.clone(), entry);
|
||||||
return id;
|
return id;
|
||||||
@ -167,7 +161,7 @@ mod cache {
|
|||||||
use setup::MTT;
|
use setup::MTT;
|
||||||
|
|
||||||
#[async_std::test]
|
#[async_std::test]
|
||||||
async fn entry_ids_are_random() {
|
async fn ids_are_random() {
|
||||||
let mtt = MTT::new().await;
|
let mtt = MTT::new().await;
|
||||||
let data1 = CacheEntry::Raw("one".to_string());
|
let data1 = CacheEntry::Raw("one".to_string());
|
||||||
let data2 = CacheEntry::Raw("two".to_string());
|
let data2 = CacheEntry::Raw("two".to_string());
|
||||||
|
Loading…
Reference in New Issue
Block a user