fix: async for init_reader

This commit is contained in:
Elijah McMorris 2024-09-24 14:35:32 -07:00
parent 5fa50cf69f
commit 47cde83c7a
Signed by: NexVeridian
SSH key fingerprint: SHA256:bsA1SKZxuEcEVHAy3gY1HUeM5ykRJl0U0kQHQn0hMg8
4 changed files with 13 additions and 7 deletions

View file

@ -26,7 +26,9 @@ fn bench(c: &mut Criterion) {
rt.block_on(async {
let db = inti_db().await.unwrap();
let reader = File_Format::new("json")
.await
.reader("tests/data/bench.json")
.await
.unwrap();
CreateVersion::Bulk

View file

@ -46,7 +46,9 @@ async fn main() -> Result<(), Error> {
sleep(Duration::from_secs(10)).await;
let pb = init_progress_bar::create_pb().await;
let reader = File_Format::new(get_wikidata_file_format().await)
.reader(get_wikidata_file_name().await)?;
.await
.reader(get_wikidata_file_name().await)
.await?;
fs::create_dir_all("data/temp").await?;
fs::remove_dir_all("data/temp").await?;

View file

@ -11,14 +11,14 @@ pub enum File_Format {
bz2,
}
impl File_Format {
pub fn new(file: &str) -> Self {
pub async fn new(file: &str) -> Self {
match file {
"json" => Self::json,
"bz2" => Self::bz2,
_ => panic!("Unknown file format"),
}
}
pub fn reader(self, file: &str) -> Result<Box<dyn BufRead>, Error> {
pub async fn reader(self, file: &str) -> Result<Box<dyn BufRead>, Error> {
let file = File::open(file)?;
match self {
File_Format::json => Ok(Box::new(BufReader::new(file))),

View file

@ -15,9 +15,11 @@ async fn inti_db() -> Result<Surreal<Db>, Error> {
Ok(db)
}
fn init_reader(file_format: &str, file_name: &str) -> Box<dyn BufRead> {
async fn init_reader(file_format: &str, file_name: &str) -> Box<dyn BufRead> {
File_Format::new(file_format)
.await
.reader(&format!("./tests/data/{}.{}", file_name, file_format))
.await
.unwrap()
}
@ -42,7 +44,7 @@ async fn entity_query(db: &Surreal<Db>) -> Result<Option<f32>, Error> {
#[tokio::test]
async fn entity_threaded(#[case] version: CreateVersion) -> Result<(), Error> {
let db = inti_db().await?;
let reader = init_reader("json", "Entity");
let reader = init_reader("json", "Entity").await;
version
.run(Some(db.clone()), reader, None, 1_000, 100)
@ -56,7 +58,7 @@ async fn entity_threaded(#[case] version: CreateVersion) -> Result<(), Error> {
async fn entity_threaded_filter() -> Result<(), Error> {
env::set_var("FILTER_PATH", "./tests/data/test_filter.surql");
let db = inti_db().await?;
let reader = init_reader("json", "bench");
let reader = init_reader("json", "bench").await;
CreateVersion::BulkFilter
.run(Some(db.clone()), reader, None, 1_000, 100)
@ -88,7 +90,7 @@ async fn property_query(db: &Surreal<Db>) -> Result<Option<f32>, Error> {
#[tokio::test]
async fn property_threaded(#[case] version: CreateVersion) -> Result<(), Error> {
let db = inti_db().await?;
let reader = init_reader("json", "Property");
let reader = init_reader("json", "Property").await;
version
.run(Some(db.clone()), reader, None, 1_000, 100)