Repo integration #15
No files matched your search
@@ -11,6 +11,8 @@ use rusqlite::Connection;
|
|||||||
use std::marker::PhantomData;
|
use std::marker::PhantomData;
|
||||||
use std::ops::{Deref, Index, IndexMut};
|
use std::ops::{Deref, Index, IndexMut};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
use std::time::Instant;
|
||||||
|
use log::debug;
|
||||||
|
|
||||||
pub trait Repository<T, D>
|
pub trait Repository<T, D>
|
||||||
where
|
where
|
||||||
@@ -158,6 +160,7 @@ impl<T: EntityData + Clone + Send + Sync, R: Repository<T, D>, D: DbLayer<T>> Qu
|
|||||||
where
|
where
|
||||||
T: Send + Sync,
|
T: Send + Sync,
|
||||||
{
|
{
|
||||||
|
let time = Instant::now();
|
||||||
self.cache.clear();
|
self.cache.clear();
|
||||||
if self.parallel {
|
if self.parallel {
|
||||||
self.cache = data_repository
|
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))
|
.map(|(i, entity)| EntityHandle::new(entity.id(), i, false))
|
||||||
.collect::<Vec<_>>(),
|
.collect::<Vec<_>>(),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
debug!("Query for {} elements (filtered {}) takes {:?}", self.len(), self.cache.len(), time.elapsed());
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn handles(&self) -> impl Iterator<Item = EntityHandle<T>> {
|
pub fn handles(&self) -> impl Iterator<Item = EntityHandle<T>> {
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
use crate::fs::*;
|
use crate::fs::*;
|
||||||
use rusqlite::Connection;
|
use rusqlite::Connection;
|
||||||
use std::ops::{Deref, DerefMut};
|
use std::ops::{Deref, DerefMut};
|
||||||
|
use log::error;
|
||||||
|
|
||||||
pub fn create_db() {
|
pub fn create_db() {
|
||||||
let db_file = db_path();
|
let db_file = db_path();
|
||||||
@@ -108,6 +109,18 @@ impl Default for SqliteConnection {
|
|||||||
|
|
||||||
impl SqliteConnection {
|
impl SqliteConnection {
|
||||||
pub fn finish(&mut self) {
|
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;
|
self.0 = None;
|
||||||
}
|
}
|
||||||
pub fn restart(&mut self) {
|
pub fn restart(&mut self) {
|
||||||
|
|||||||
Reference in new issue
Block a user