Merge pull request #576 from ppamorim/fix-bench

Fix benchmark
This commit is contained in:
Clément Renault 2020-04-02 12:23:31 +02:00 committed by GitHub
commit 26225a2fdf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 8 deletions

View File

@ -4,3 +4,4 @@
- Add support for aligned crop in search result (#543) - Add support for aligned crop in search result (#543)
- Sanitize the content displayed in the web interface (#539) - Sanitize the content displayed in the web interface (#539)
- Add support of nested null, boolean and seq values (#571 and #568, #574) - Add support of nested null, boolean and seq values (#571 and #568, #574)
- Fixed the core benchmark (#576)

View File

@ -1,5 +1,4 @@
{ {
"primaryKey": "id",
"searchableAttributes": ["title", "overview"], "searchableAttributes": ["title", "overview"],
"displayedAttributes": [ "displayedAttributes": [
"id", "id",

View File

@ -4,11 +4,14 @@ extern crate assert_matches;
use std::sync::mpsc; use std::sync::mpsc;
use std::path::Path; use std::path::Path;
use std::fs; use std::fs::File;
use std::io::BufReader;
use std::iter; use std::iter;
use meilisearch_core::Database; use meilisearch_core::Database;
use meilisearch_core::{ProcessedUpdateResult, UpdateStatus}; use meilisearch_core::{ProcessedUpdateResult, UpdateStatus};
use meilisearch_core::settings::{Settings, SettingsUpdate};
use meilisearch_schema::Schema;
use serde_json::Value; use serde_json::Value;
use criterion::{criterion_group, criterion_main, Criterion, BenchmarkId}; use criterion::{criterion_group, criterion_main, Criterion, BenchmarkId};
@ -25,21 +28,27 @@ fn prepare_database(path: &Path) -> Database {
database.set_update_callback(Box::new(update_fn)); database.set_update_callback(Box::new(update_fn));
let schema = { let mut writer = db.main_write_txn().unwrap();
let path = concat!(env!("CARGO_MANIFEST_DIR"), "/../datasets/movies/schema.toml"); index.main.put_schema(&mut writer, &Schema::with_primary_key("id")).unwrap();
let string = fs::read_to_string(path).expect("find schema"); writer.commit().unwrap();
toml::from_str(&string).unwrap()
let settings_update: SettingsUpdate = {
let path = concat!(env!("CARGO_MANIFEST_DIR"), "/../datasets/movies/settings.json");
let file = File::open(path).unwrap();
let reader = BufReader::new(file);
let settings: Settings = serde_json::from_reader(reader).unwrap();
settings.into_update().unwrap()
}; };
let mut update_writer = db.update_write_txn().unwrap(); let mut update_writer = db.update_write_txn().unwrap();
let _update_id = index.schema_update(&mut update_writer, schema).unwrap(); let _update_id = index.settings_update(&mut update_writer, settings_update).unwrap();
update_writer.commit().unwrap(); update_writer.commit().unwrap();
let mut additions = index.documents_addition(); let mut additions = index.documents_addition();
let json: Value = { let json: Value = {
let path = concat!(env!("CARGO_MANIFEST_DIR"), "/../datasets/movies/movies.json"); let path = concat!(env!("CARGO_MANIFEST_DIR"), "/../datasets/movies/movies.json");
let movies_file = fs::File::open(path).expect("find movies"); let movies_file = File::open(path).expect("find movies");
serde_json::from_reader(movies_file).unwrap() serde_json::from_reader(movies_file).unwrap()
}; };