mirror of
https://github.com/NexVeridian/wikidata-to-surrealdb.git
synced 2025-09-02 01:49:13 +00:00
with_capacity
This commit is contained in:
parent
2ded1d5b1b
commit
17a115f473
1 changed files with 3 additions and 17 deletions
20
src/utils.rs
20
src/utils.rs
|
@ -106,11 +106,10 @@ pub async fn create_db_entities_bulk(
|
||||||
.filter(|line| line != "[" && line != "]")
|
.filter(|line| line != "[" && line != "]")
|
||||||
.collect::<Vec<String>>();
|
.collect::<Vec<String>>();
|
||||||
|
|
||||||
let mut data_vec: Vec<EntityMini> = Vec::new();
|
let mut data_vec: Vec<EntityMini> = Vec::with_capacity(batch_size);
|
||||||
let mut claims_vec: Vec<Claims> = Vec::with_capacity(batch_size);
|
let mut claims_vec: Vec<Claims> = Vec::with_capacity(batch_size);
|
||||||
let mut property_vec: Vec<EntityMini> = Vec::new();
|
let mut property_vec: Vec<EntityMini> = Vec::with_capacity(batch_size);
|
||||||
let mut lexeme_vec: Vec<EntityMini> = Vec::new();
|
let mut lexeme_vec: Vec<EntityMini> = Vec::with_capacity(batch_size);
|
||||||
let mut first_loop = true;
|
|
||||||
|
|
||||||
for line in lines {
|
for line in lines {
|
||||||
let json: Value = from_str(&line).expect("Failed to parse JSON");
|
let json: Value = from_str(&line).expect("Failed to parse JSON");
|
||||||
|
@ -123,19 +122,6 @@ pub async fn create_db_entities_bulk(
|
||||||
_ => panic!("Unknown table"),
|
_ => panic!("Unknown table"),
|
||||||
}
|
}
|
||||||
claims_vec.push(claims);
|
claims_vec.push(claims);
|
||||||
|
|
||||||
if first_loop {
|
|
||||||
first_loop = false;
|
|
||||||
if !data_vec.is_empty() {
|
|
||||||
data_vec.reserve(batch_size);
|
|
||||||
}
|
|
||||||
if !property_vec.is_empty() {
|
|
||||||
property_vec.reserve(batch_size);
|
|
||||||
}
|
|
||||||
if !lexeme_vec.is_empty() {
|
|
||||||
lexeme_vec.reserve(batch_size);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
db.insert::<Vec<EntityMini>>("Entity")
|
db.insert::<Vec<EntityMini>>("Entity")
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue