optimization fix

This commit is contained in:
leca 2024-04-14 12:48:04 +03:00
parent 47fd5b3b9d
commit c2e6788a85
3 changed files with 13 additions and 6 deletions

View File

@ -105,10 +105,10 @@ fn deduplicate(entries: &Vec<DictionaryEntry>) -> Vec<DictionaryEntry> {
}
fn write_to_database(dict: &Vec<DictionaryEntry>) {
let conn = Connection::open(get_db_path()).unwrap();
let mut conn = Connection::open(get_db_path()).unwrap();
let tx = conn.transaction().unwrap();
for line in dict.iter() {
match conn.execute("INSERT OR REPLACE INTO cards (id, hieroglyph, reading, translation) VALUES ((SELECT id FROM cards WHERE hieroglyph = ?1), ?1, ?2, ?3)", [&line.hieroglyph, &line.reading, &line.translation]) {
match tx.execute("INSERT OR REPLACE INTO cards (id, hieroglyph, reading, translation) VALUES ((SELECT id FROM cards WHERE hieroglyph = ?1), ?1, ?2, ?3)", [&line.hieroglyph, &line.reading, &line.translation]) {
Ok(_) => (),
Err(e) => {
println!("{e}" );
@ -116,12 +116,13 @@ fn write_to_database(dict: &Vec<DictionaryEntry>) {
}
};
}
tx.commit().unwrap();
}
pub fn import(path: &String) {
let dictionary = read_and_parse(path);
let dictionary = deduplicate(&dictionary);
// write_to_database(&dictionary);
write_to_database(&dictionary);
}
// pub fn write_to_file(path: &String, dict: &Vec<Entry>) {

View File

@ -114,7 +114,10 @@ impl MemoryCardsEditScene {
.unwrap();
let cards_iter = stmt
.query_map([], |row| {
let image_path: String = row.get(0).unwrap();
let image_path: String = match row.get(0){
Ok(path) => path,
Err(_) => String::from("")
};
let image_path: String = get_images_store_path() + &image_path;
let hieroglyph: String = row.get(1).unwrap();
let reading: String = row.get(2).unwrap();

View File

@ -45,7 +45,10 @@ impl CardDisplay {
let random_card_iter = stmt.query_map((), |row| {
Ok(
Card {
imagename: row.get(0).unwrap(),
imagename: match row.get(0) {
Ok(value) => value,
Err(e) => String::from("")
},
hieroglyph: row.get(1).unwrap()
}
)