Faster new set initializing
This commit is contained in:
Generated
+45
-36
@@ -41,6 +41,15 @@ dependencies = [
|
|||||||
"memchr",
|
"memchr",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "alloca"
|
||||||
|
version = "0.4.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "e5a7d05ea6aea7e9e64d25b9156ba2fee3fdd659e34e41063cd2fc7cd020d7f4"
|
||||||
|
dependencies = [
|
||||||
|
"cc",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "alsa"
|
name = "alsa"
|
||||||
version = "0.11.0"
|
version = "0.11.0"
|
||||||
@@ -814,25 +823,24 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "criterion"
|
name = "criterion"
|
||||||
version = "0.5.1"
|
version = "0.8.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "f2b12d017a929603d80db1831cd3a24082f8137ce19c69e6447f54f5fc8d692f"
|
checksum = "950046b2aa2492f9a536f5f4f9a3de7b9e2476e575e05bd6c333371add4d98f3"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"alloca",
|
||||||
"anes",
|
"anes",
|
||||||
"cast",
|
"cast",
|
||||||
"ciborium",
|
"ciborium",
|
||||||
"clap",
|
"clap",
|
||||||
"criterion-plot",
|
"criterion-plot",
|
||||||
"is-terminal",
|
|
||||||
"itertools",
|
"itertools",
|
||||||
"num-traits",
|
"num-traits",
|
||||||
"once_cell",
|
|
||||||
"oorandom",
|
"oorandom",
|
||||||
|
"page_size",
|
||||||
"plotters",
|
"plotters",
|
||||||
"rayon",
|
"rayon",
|
||||||
"regex",
|
"regex",
|
||||||
"serde",
|
"serde",
|
||||||
"serde_derive",
|
|
||||||
"serde_json",
|
"serde_json",
|
||||||
"tinytemplate",
|
"tinytemplate",
|
||||||
"walkdir",
|
"walkdir",
|
||||||
@@ -840,9 +848,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "criterion-plot"
|
name = "criterion-plot"
|
||||||
version = "0.5.0"
|
version = "0.8.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "6b50826342786a51a89e2da3a28f1c32b06e387201bc2d19791f622c673706b1"
|
checksum = "d8d80a2f4f5b554395e47b5d8305bc3d27813bacb73493eb1001e8f76dae29ea"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cast",
|
"cast",
|
||||||
"itertools",
|
"itertools",
|
||||||
@@ -1555,12 +1563,21 @@ dependencies = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "hashlink"
|
name = "hashbrown"
|
||||||
version = "0.11.0"
|
version = "0.17.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "ea0b22561a9c04a7cb1a302c013e0259cd3b4bb619f145b32f72b8b4bcbed230"
|
checksum = "ed5909b6e89a2db4456e54cd5f673791d7eca6732202bbf2a9cc504fe2f9b84a"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"hashbrown 0.16.1",
|
"foldhash 0.2.0",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "hashlink"
|
||||||
|
version = "0.12.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "32069d97bb81e38fa67eab65e3393bf804bb85969f2bc06bf13f64aef5aba248"
|
||||||
|
dependencies = [
|
||||||
|
"hashbrown 0.17.1",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -1581,12 +1598,6 @@ version = "0.4.3"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70"
|
checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "hex-literal"
|
|
||||||
version = "1.1.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "e712f64ec3850b98572bffac52e2c6f282b29fe6c5fa6d42334b30be438d95c1"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "hexf-parse"
|
name = "hexf-parse"
|
||||||
version = "0.2.1"
|
version = "0.2.1"
|
||||||
@@ -2064,22 +2075,11 @@ dependencies = [
|
|||||||
"serde",
|
"serde",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "is-terminal"
|
|
||||||
version = "0.4.17"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "3640c1c38b8e4e43584d8df18be5fc6b0aa314ce6ebf51b53313d4306cca8e46"
|
|
||||||
dependencies = [
|
|
||||||
"hermit-abi",
|
|
||||||
"libc",
|
|
||||||
"windows-sys 0.61.2",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "itertools"
|
name = "itertools"
|
||||||
version = "0.10.5"
|
version = "0.13.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "b0fd2260e829bddf4cb6ea802289de2f86d6a7a690192fbe91b3f46e0f2c8473"
|
checksum = "413ee7dfc52ee1a4949ceeb7dbc8a33f2d6c088194d9f922fb8318faf1f01186"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"either",
|
"either",
|
||||||
]
|
]
|
||||||
@@ -2098,10 +2098,8 @@ dependencies = [
|
|||||||
"criterion",
|
"criterion",
|
||||||
"dirs",
|
"dirs",
|
||||||
"hex",
|
"hex",
|
||||||
"hex-literal",
|
|
||||||
"iced",
|
"iced",
|
||||||
"rand",
|
"rand",
|
||||||
"rayon",
|
|
||||||
"reqwest",
|
"reqwest",
|
||||||
"rhai",
|
"rhai",
|
||||||
"rodio",
|
"rodio",
|
||||||
@@ -2229,10 +2227,11 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "libsqlite3-sys"
|
name = "libsqlite3-sys"
|
||||||
version = "0.37.0"
|
version = "0.38.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "b1f111c8c41e7c61a49cd34e44c7619462967221a6443b0ec299e0ac30cfb9b1"
|
checksum = "f6c19a05435c21ac299d71b6a9c13db3e3f47c520517d58990a462a1397a61db"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"cc",
|
||||||
"pkg-config",
|
"pkg-config",
|
||||||
"vcpkg",
|
"vcpkg",
|
||||||
]
|
]
|
||||||
@@ -3074,6 +3073,16 @@ dependencies = [
|
|||||||
"ttf-parser",
|
"ttf-parser",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "page_size"
|
||||||
|
version = "0.6.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "30d5b2194ed13191c1999ae0704b7839fb18384fa22e49b57eeaa97d79ce40da"
|
||||||
|
dependencies = [
|
||||||
|
"libc",
|
||||||
|
"winapi",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "parking"
|
name = "parking"
|
||||||
version = "2.2.1"
|
version = "2.2.1"
|
||||||
@@ -3569,9 +3578,9 @@ checksum = "7204ed6420f698836b76d4d5c2ec5dec7585fd5c3a788fd1cde855d1de598239"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "rusqlite"
|
name = "rusqlite"
|
||||||
version = "0.39.0"
|
version = "0.40.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "a0d2b0146dd9661bf67bb107c0bb2a55064d556eeb3fc314151b957f313bcd4e"
|
checksum = "11438310b19e3109b6446c33d1ed5e889428cf2e278407bc7896bc4aaea43323"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bitflags 2.10.0",
|
"bitflags 2.10.0",
|
||||||
"chrono",
|
"chrono",
|
||||||
|
|||||||
+2
-4
@@ -11,18 +11,16 @@ serde = { version = "1.0.228", features = ["derive"] }
|
|||||||
serde_json = "1.0.149"
|
serde_json = "1.0.149"
|
||||||
rhai = "1.24.0"
|
rhai = "1.24.0"
|
||||||
chrono = "0.4.44"
|
chrono = "0.4.44"
|
||||||
rusqlite = { version = "0.39.0", features = ["chrono"] }
|
rusqlite = { version = "0.40.1", features = ["chrono", "bundled"] }
|
||||||
reqwest = { version = "0", features = ["json", "stream", "multipart"] }
|
reqwest = { version = "0", features = ["json", "stream", "multipart"] }
|
||||||
rodio = "0.22.2"
|
rodio = "0.22.2"
|
||||||
sha2 = "0.11.0"
|
sha2 = "0.11.0"
|
||||||
tokio = { version = "1.50.0", features = ["rt", "rt-multi-thread", "macros"] }
|
tokio = { version = "1.50.0", features = ["rt", "rt-multi-thread", "macros"] }
|
||||||
rayon = "1.12.0"
|
|
||||||
hex = "0.4.3"
|
hex = "0.4.3"
|
||||||
hex-literal = "1.1.0"
|
|
||||||
zstd = "0.13.3"
|
zstd = "0.13.3"
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
criterion = "0.5"
|
criterion = "0.8.2"
|
||||||
|
|
||||||
[[bench]]
|
[[bench]]
|
||||||
name = "split_bench" # Имя файла в benches/ без расширения
|
name = "split_bench" # Имя файла в benches/ без расширения
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
use crate::lang::CardStatistics;
|
use crate::lang::CardStatistics;
|
||||||
use crate::repetitions::CardSetSettings;
|
use crate::repetitions::CardSetSettings;
|
||||||
use rusqlite::Connection;
|
use rusqlite::Connection;
|
||||||
|
use std::time::Instant;
|
||||||
|
|
||||||
pub fn load_stats_of_set(set: &CardSetSettings, connection: &Connection) -> Vec<CardStatistics> {
|
pub fn load_stats_of_set(set: &CardSetSettings, connection: &Connection) -> Vec<CardStatistics> {
|
||||||
let mut stmt = connection.prepare("SELECT id, word_id, score, last_opened FROM card_stats WHERE set_id = ?1").unwrap();
|
let mut stmt = connection.prepare("SELECT id, word_id, score, last_opened FROM card_stats WHERE set_id = ?1").unwrap();
|
||||||
@@ -22,7 +23,37 @@ pub fn load_stats_of_set(set: &CardSetSettings, connection: &Connection) -> Vec<
|
|||||||
buffer
|
buffer
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
pub fn add_stat_list(stat: &mut Vec<CardStatistics>, connection: &Connection) {
|
||||||
|
let inserting = stat.iter().map(|stat| format!("({}, {}, {}, {})", stat.word_id.to_string(), stat.set_id.to_string(), stat.score.to_string(), stat.last_open.timestamp().to_string())).collect::<Vec<_>>().join(", ");
|
||||||
|
let query = format!("INSERT INTO card_stats (word_id, set_id, score, last_opened) VALUES {}", inserting);
|
||||||
|
let count = connection
|
||||||
|
.execute(
|
||||||
|
query.as_str(),
|
||||||
|
(
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
if count.is_err() {
|
||||||
|
println!("{}", count.unwrap_err());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let last_index : u32 = connection.query_one("SELECT seq from sqlite_sequence WHERE name == ?1", ("card_stats".to_string(),), |row| row.get(0)).unwrap();
|
||||||
|
|
||||||
|
let start_index = last_index - (count.unwrap() as u32) + 1;
|
||||||
|
|
||||||
|
let mut index = 0;
|
||||||
|
for id in start_index..=last_index {
|
||||||
|
stat[index].id = id as u32;
|
||||||
|
index += 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
pub fn add_stat(stat: &mut CardStatistics, connection: &Connection) {
|
pub fn add_stat(stat: &mut CardStatistics, connection: &Connection) {
|
||||||
|
let time = Instant::now();
|
||||||
let index = connection
|
let index = connection
|
||||||
.query_row(
|
.query_row(
|
||||||
"INSERT INTO card_stats (word_id, set_id, score, last_opened) VALUES (?1, ?2, ?3, ?4) RETURNING id",
|
"INSERT INTO card_stats (word_id, set_id, score, last_opened) VALUES (?1, ?2, ?3, ?4) RETURNING id",
|
||||||
@@ -37,9 +68,12 @@ pub fn add_stat(stat: &mut CardStatistics, connection: &Connection) {
|
|||||||
.unwrap_or_else(|e| {println!("{}", e); 0});
|
.unwrap_or_else(|e| {println!("{}", e); 0});
|
||||||
|
|
||||||
stat.id = index;
|
stat.id = index;
|
||||||
|
println!("Added stat: {}", time.elapsed().as_millis());
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn update_stat_score(stat: &CardStatistics, connection: &Connection){
|
pub fn update_stat_score(stat: &CardStatistics, connection: &Connection){
|
||||||
|
let time = Instant::now();
|
||||||
|
|
||||||
connection
|
connection
|
||||||
.execute(
|
.execute(
|
||||||
"UPDATE card_stats SET score = ?1, last_opened = ?2 WHERE id = ?3",
|
"UPDATE card_stats SET score = ?1, last_opened = ?2 WHERE id = ?3",
|
||||||
@@ -50,6 +84,8 @@ pub fn update_stat_score(stat: &CardStatistics, connection: &Connection){
|
|||||||
),
|
),
|
||||||
)
|
)
|
||||||
.unwrap_or_else(|e| {println!("{}", e); 0});
|
.unwrap_or_else(|e| {println!("{}", e); 0});
|
||||||
|
println!("Updated stat: {}", time.elapsed().as_millis());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn delete_stat(stat: &CardStatistics, connection: &Connection) {
|
pub fn delete_stat(stat: &CardStatistics, connection: &Connection) {
|
||||||
|
|||||||
@@ -326,6 +326,7 @@ impl DictionaryState {
|
|||||||
if !self.search.is_empty() {
|
if !self.search.is_empty() {
|
||||||
if word.key.contains(&self.search) == false
|
if word.key.contains(&self.search) == false
|
||||||
&& word.value.contains(&self.search) == false
|
&& word.value.contains(&self.search) == false
|
||||||
|
&& word.tags.contains(&self.search) == false
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|||||||
+13
-10
@@ -1,6 +1,5 @@
|
|||||||
use crate::data_provider::card_stats::{
|
use crate::data_provider::card_stats::{add_stat_list, delete_stat, load_stats_of_set, update_stat_score};
|
||||||
add_stat, delete_stat, load_stats_of_set, update_stat_score,
|
use crate::data_provider::history::{push_note, HistoryItem};
|
||||||
};
|
|
||||||
use crate::repetitions::CardSetSettings;
|
use crate::repetitions::CardSetSettings;
|
||||||
use crate::AppState;
|
use crate::AppState;
|
||||||
use chrono::{DateTime, Utc};
|
use chrono::{DateTime, Utc};
|
||||||
@@ -13,7 +12,7 @@ use serde::{Deserialize, Serialize};
|
|||||||
use std::cmp::min;
|
use std::cmp::min;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::sync::{Arc, Mutex};
|
use std::sync::{Arc, Mutex};
|
||||||
use crate::data_provider::history::{push_note, HistoryItem};
|
use std::time::Instant;
|
||||||
|
|
||||||
const MAX_HISTORY_LEN: usize = 20;
|
const MAX_HISTORY_LEN: usize = 20;
|
||||||
const MAX_HISTORY_LEN_PART: f32 = 0.33;
|
const MAX_HISTORY_LEN_PART: f32 = 0.33;
|
||||||
@@ -329,7 +328,7 @@ impl CardSet {
|
|||||||
let saved_ids = current_set.iter().map(|l| l.word_id).collect::<Vec<u32>>();
|
let saved_ids = current_set.iter().map(|l| l.word_id).collect::<Vec<u32>>();
|
||||||
let word_ids = last_list.iter().map(|l| l.id).collect::<Vec<u32>>();
|
let word_ids = last_list.iter().map(|l| l.id).collect::<Vec<u32>>();
|
||||||
|
|
||||||
last_list
|
let new_stats: &mut Vec<CardStatistics> = &mut last_list
|
||||||
.iter()
|
.iter()
|
||||||
.filter(|word| !saved_ids.contains(&word.id))
|
.filter(|word| !saved_ids.contains(&word.id))
|
||||||
.map(|word| CardStatistics {
|
.map(|word| CardStatistics {
|
||||||
@@ -338,12 +337,16 @@ impl CardSet {
|
|||||||
last_open: Utc::now(),
|
last_open: Utc::now(),
|
||||||
score: 1,
|
score: 1,
|
||||||
set_id: settings.id.clone(),
|
set_id: settings.id.clone(),
|
||||||
})
|
}).collect();
|
||||||
.for_each(|mut new_statistic| {
|
|
||||||
add_stat(&mut new_statistic, &state_locked.connection);
|
|
||||||
current_set.push(new_statistic);
|
|
||||||
});
|
|
||||||
|
|
||||||
|
let time = Instant::now();
|
||||||
|
|
||||||
|
if !new_stats.is_empty() {
|
||||||
|
add_stat_list(new_stats, &state_locked.connection);
|
||||||
|
current_set.append(new_stats);
|
||||||
|
}
|
||||||
|
|
||||||
|
println!("Added {} stats: {}", new_stats.len(), time.elapsed().as_millis());
|
||||||
let mut index = 0;
|
let mut index = 0;
|
||||||
for stat in current_set.clone() {
|
for stat in current_set.clone() {
|
||||||
if !word_ids.contains(&stat.word_id) {
|
if !word_ids.contains(&stat.word_id) {
|
||||||
|
|||||||
Reference in New Issue
Block a user