Repository: meilisearch/meilisearch
File: milli/src/update/facet/bulk.rs (Rust)

Code before:
                }
                let value: KvReader<DelAdd> = KvReader::new(value);

                // DB is empty, it is safe to ignore Del operations
                let Some(value) = value.get(DelAdd::Addition) else {
                    continue;
                };

                buffer.clear();
                // the group size for level 0
                buffer.push(1);
                // then we extend the buffer with the docids bitmap
                buffer.extend_from_slice(value);
                unsafe { database.append(key, &buffer)? };
            }
        } else {
            let mut buffer = Vec::new();
            let database = self.db.remap_types::<ByteSlice, ByteSlice>();

            let mut cursor = delta_data.into_cursor()?;
            while let Some((key, value)) = cursor.move_on_next()? {
                if !valid_lmdb_key(key) {
                    continue;
                }

                let value: KvReader<DelAdd> = KvReader::new(value);

                // the value is a CboRoaringBitmap, but I still need to prepend the
                // group size for level 0 (= 1) to it
                buffer.clear();
                buffer.push(1);
                // then we extend the buffer with the docids bitmap
                match database.get(wtxn, key)? {
                    Some(prev_value) => {
                        let old_bitmap = &prev_value[1..];
                        CboRoaringBitmapCodec::merge_deladd_into(value, old_bitmap, &mut buffer)?;
                    }
                    None => {
                        // it is safe to ignore the del in that case.
                        let Some(value) = value.get(DelAdd::Addition) else {
                            // won't put the key in DB as the value would be empty
                            continue;
                        };

                        buffer.extend_from_slice(value);
                    }
                };
                database.put(wtxn, key, &buffer)?;
            }
        }
        Ok(())

Review comment (suggestion):
```suggestion
                let value = KvReaderDelAdd::new(value);
```

Code after:
                let value = KvReaderDelAdd::new(value);

                // DB is empty, it is safe to ignore Del operations
                let Some(value) = value.get(DelAdd::Addition) else {
                    continue;
                };

                buffer.clear();
                // the group size for level 0
                buffer.push(1);
                // then we extend the buffer with the docids bitmap
                buffer.extend_from_slice(value);
                unsafe { database.append(key, &buffer)? };
            }
        } else {
            let mut buffer = Vec::new();
            let database = self.db.remap_types::<ByteSlice, ByteSlice>();

            let mut cursor = delta_data.into_cursor()?;
            while let Some((key, value)) = cursor.move_on_next()? {
                if !valid_lmdb_key(key) {
                    continue;
                }

                let value = KvReaderDelAdd::new(value);

                // the value is a CboRoaringBitmap, but I still need to prepend the
                // group size for level 0 (= 1) to it
                buffer.clear();
                buffer.push(1);
                // then we extend the buffer with the docids bitmap
                match database.get(wtxn, key)? {
                    Some(prev_value) => {
                        // prev_value is the group size for level 0, followed by the previous bitmap.
                        let old_bitmap = &prev_value[1..];
                        CboRoaringBitmapCodec::merge_deladd_into(value, old_bitmap, &mut buffer)?;
                    }
                    None => {
                        // it is safe to ignore the del in that case.
                        let Some(value) = value.get(DelAdd::Addition) else {
                            // won't put the key in DB as the value would be empty
                            continue;
                        };

                        buffer.extend_from_slice(value);
                    }
                };
                database.put(wtxn, key, &buffer)?;
            }
        }
        Ok(())