Repo integration #15

Merged
micialware merged 35 commits from repo-integration into master 2026-09-09 12:47:42 +03:00
2 changed files with 18 additions and 0 deletions
Showing only changes of commit 294f0e8b98 - Show all commits

No files matched your search

+5
View File
@@ -11,6 +11,8 @@ use rusqlite::Connection;
use std::marker::PhantomData;
use std::ops::{Deref, Index, IndexMut};
use std::sync::Arc;
use std::time::Instant;
use log::debug;
pub trait Repository<T, D>
where
@@ -158,6 +160,7 @@ impl<T: EntityData + Clone + Send + Sync, R: Repository<T, D>, D: DbLayer<T>> Qu
where
T: Send + Sync,
{
let time = Instant::now();
self.cache.clear();
if self.parallel {
self.cache = data_repository
@@ -186,6 +189,8 @@ impl<T: EntityData + Clone + Send + Sync, R: Repository<T, D>, D: DbLayer<T>> Qu
.map(|(i, entity)| EntityHandle::new(entity.id(), i, false))
.collect::<Vec<_>>(),
);
debug!("Query for {} elements (filtered {}) takes {:?}", self.len(), self.cache.len(), time.elapsed());
}
pub fn handles(&self) -> impl Iterator<Item = EntityHandle<T>> {
+13
View File
@@ -1,6 +1,7 @@
use crate::fs::*;
use rusqlite::Connection;
use std::ops::{Deref, DerefMut};
use log::error;
pub fn create_db() {
let db_file = db_path();
@@ -108,6 +109,18 @@ impl Default for SqliteConnection {
impl SqliteConnection {
pub fn finish(&mut self) {
let connection = self.0.take().unwrap();
connection
.query_row("PRAGMA wal_checkpoint(TRUNCATE)", [], |_| Ok(()))
.unwrap_or_else(|e| {
error!("Ошибка при checkpoint WAL: {e}");
});
connection
.query_row("PRAGMA optimize", [], |_| Ok(()))
.unwrap_or_else(|e| {
error!("Ошибка при оптимизации БД: {e}");
});
self.0 = None;
}
pub fn restart(&mut self) {