Take into account small Review requests

This commit is contained in:
ManyTheFish 2023-06-20 18:25:10 +02:00
parent 59f64a5256
commit 63ca25290b

View File

@ -57,12 +57,9 @@ impl<'ctx> DatabaseCache<'ctx> {
KC: BytesEncode<'v>, KC: BytesEncode<'v>,
DC: BytesDecodeOwned, DC: BytesDecodeOwned,
{ {
match cache.entry(cache_key) { if let Entry::Vacant(entry) = cache.entry(cache_key) {
Entry::Occupied(_) => {} let bitmap_ptr = db.get(txn, db_key)?.map(Cow::Borrowed);
Entry::Vacant(entry) => { entry.insert(bitmap_ptr);
let bitmap_ptr = db.get(txn, db_key)?.map(Cow::Borrowed);
entry.insert(bitmap_ptr);
}
} }
match cache.get(&cache_key).unwrap() { match cache.get(&cache_key).unwrap() {
@ -90,30 +87,27 @@ impl<'ctx> DatabaseCache<'ctx> {
DC: BytesDecodeOwned, DC: BytesDecodeOwned,
KC::EItem: Sized, KC::EItem: Sized,
{ {
match cache.entry(cache_key) { if let Entry::Vacant(entry) = cache.entry(cache_key) {
Entry::Occupied(_) => {} let bitmap_ptr: Option<Cow<'ctx, [u8]>> = match db_keys {
Entry::Vacant(entry) => { [] => None,
let bitmap_ptr: Option<Cow<'ctx, [u8]>> = match db_keys { [key] => db.get(txn, key)?.map(Cow::Borrowed),
[] => None, keys => {
[key] => db.get(txn, key)?.map(Cow::Borrowed), let bitmaps = keys
keys => { .iter()
let bitmaps = keys .filter_map(|key| db.get(txn, key).transpose())
.iter() .map(|v| v.map(Cow::Borrowed))
.filter_map(|key| db.get(txn, key).transpose()) .collect::<std::result::Result<Vec<Cow<[u8]>>, _>>()?;
.map(|v| v.map(Cow::Borrowed))
.collect::<std::result::Result<Vec<Cow<[u8]>>, _>>()?;
if bitmaps.is_empty() { if bitmaps.is_empty() {
None None
} else { } else {
Some(merger(&[], &bitmaps[..])?) Some(merger(&[], &bitmaps[..])?)
}
} }
}; }
};
entry.insert(bitmap_ptr); entry.insert(bitmap_ptr);
} }
};
match cache.get(&cache_key).unwrap() { match cache.get(&cache_key).unwrap() {
Some(Cow::Borrowed(bytes)) => { Some(Cow::Borrowed(bytes)) => {