Fix data access method and solve import page

This commit is contained in:
micialware committed 2026-09-04 11:37:19 +03:00
1 parent 532640058e
commit 9a7578727b
2 files changed
+35 -41

No files matched your search

+24 -30
View File
@@ -432,18 +432,29 @@ impl ImportState {
info!("{}", group.name);
Task::perform(
async move {
let words_list = spawn_blocking(move || {
spawn_blocking(move || {
let temp_file_path = temp_import_path();
let connection = Connection::open(&temp_file_path).map_err(|_| OpenFileError)?;
let import_list = get_words_of_group(&connection, group.id)?;
let mut words_list = Vec::with_capacity(import_list.len());
let map_indices = Self::get_mapping_indices(&group);
let group_handle;
{
let group_entity = WordGroup {
id: 0.into(),
name: group.name.clone(),
};
let mut groups_repo = state.word_groups.write();
group_handle = groups_repo.create_now(group_entity)?;
}
let group_id = group_handle.id;
for import in import_list {
let mut word = WordData::new();
word.tags = import.tags.trim().replace(" ", ", ");
word.group_id = group_id;
for (dest, indices) in &map_indices {
let collected_string = Self::collect_strings(
&import.fields,
@@ -470,37 +481,20 @@ impl ImportState {
words_list.push(word);
}
Ok::<_, NotificationData>(words_list)
let mut words_repo = state.dictionary.write();
let mut index = 0;
let total_len = words_list.len() as f32 / 1024.0;
for words in &mut words_list.chunks_mut(1024) {
words_repo.create_now_many(words)?;
index += 1;
let mut progress = progress.lock();
*progress = (index as f32 / total_len).min(1.0);
}
Ok(())
})
.await
.unwrap()?;
let group_handle = {
let group_entity = WordGroup {
id: 0.into(),
name: group.name.clone(),
};
let mut groups_repo = state.word_groups.write();
groups_repo.create_now(group_entity)?
};
let group_id = group_handle.id;
let mut words_list = words_list;
for word in &mut words_list {
word.group_id = group_id;
}
let mut words_repo = state.dictionary.write();
let mut index = 0;
let total_len = words_list.len() as f32 / 1024.0;
for words in &mut words_list.chunks_mut(1024) {
words_repo.create_now_many(words)?;
index += 1;
let mut progress = progress.lock();
*progress = (index as f32 / total_len).min(1.0);
}
Ok(())
.unwrap()
},
|r: Result<(), NotificationData>| match r {
Ok(_) => RootMessage::Import(ImportFinished),