mirror of
https://github.com/meilisearch/MeiliSearch
synced 2024-11-26 14:54:27 +01:00
Prefer using iterator put_current instead of a get put method
This commit is contained in:
parent
e63fdf2b22
commit
a30206a665
@ -108,13 +108,17 @@ fn merge_into_lmdb_database(
|
|||||||
},
|
},
|
||||||
WriteMethod::GetMergePut => {
|
WriteMethod::GetMergePut => {
|
||||||
while let Some((k, v)) = in_iter.next()? {
|
while let Some((k, v)) = in_iter.next()? {
|
||||||
match database.get::<_, ByteSlice, ByteSlice>(wtxn, k)? {
|
let mut iter = database.prefix_iter_mut::<_, ByteSlice, ByteSlice>(wtxn, k)?;
|
||||||
Some(old_val) => {
|
match iter.next().transpose()? {
|
||||||
|
Some((key, old_val)) if key == k => {
|
||||||
let vals = vec![Cow::Borrowed(old_val), Cow::Borrowed(v)];
|
let vals = vec![Cow::Borrowed(old_val), Cow::Borrowed(v)];
|
||||||
let val = merge(k, &vals).expect("merge failed");
|
let val = merge(k, &vals).expect("merge failed");
|
||||||
database.put::<_, ByteSlice, ByteSlice>(wtxn, k, &val)?
|
iter.put_current(k, &val)?;
|
||||||
|
},
|
||||||
|
_ => {
|
||||||
|
drop(iter);
|
||||||
|
database.put::<_, ByteSlice, ByteSlice>(wtxn, k, v)?;
|
||||||
},
|
},
|
||||||
None => database.put::<_, ByteSlice, ByteSlice>(wtxn, k, v)?,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -145,13 +149,17 @@ fn write_into_lmdb_database(
|
|||||||
},
|
},
|
||||||
WriteMethod::GetMergePut => {
|
WriteMethod::GetMergePut => {
|
||||||
while let Some((k, v)) = reader.next()? {
|
while let Some((k, v)) = reader.next()? {
|
||||||
match database.get::<_, ByteSlice, ByteSlice>(wtxn, k)? {
|
let mut iter = database.prefix_iter_mut::<_, ByteSlice, ByteSlice>(wtxn, k)?;
|
||||||
Some(old_val) => {
|
match iter.next().transpose()? {
|
||||||
|
Some((key, old_val)) if key == k => {
|
||||||
let vals = vec![Cow::Borrowed(old_val), Cow::Borrowed(v)];
|
let vals = vec![Cow::Borrowed(old_val), Cow::Borrowed(v)];
|
||||||
let val = merge(k, &vals).expect("merge failed");
|
let val = merge(k, &vals).expect("merge failed");
|
||||||
database.put::<_, ByteSlice, ByteSlice>(wtxn, k, &val)?
|
iter.put_current(k, &val)?;
|
||||||
|
},
|
||||||
|
_ => {
|
||||||
|
drop(iter);
|
||||||
|
database.put::<_, ByteSlice, ByteSlice>(wtxn, k, v)?;
|
||||||
},
|
},
|
||||||
None => database.put::<_, ByteSlice, ByteSlice>(wtxn, k, v)?,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user