only disable sqlite synchronous mode on initial update
parent
ecaea693c6
commit
a91711adc8
|
@ -48,7 +48,11 @@ fn initialize_types(connection: &UpEndConnection) -> Result<()> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn rescan_vault(db: Arc<UpEndDatabase>, job_container: Arc<RwLock<JobContainer>>) {
|
pub async fn rescan_vault(
|
||||||
|
db: Arc<UpEndDatabase>,
|
||||||
|
job_container: Arc<RwLock<JobContainer>>,
|
||||||
|
initial: bool,
|
||||||
|
) {
|
||||||
let job_id = job_container
|
let job_id = job_container
|
||||||
.write()
|
.write()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
@ -57,7 +61,8 @@ pub async fn rescan_vault(db: Arc<UpEndDatabase>, job_container: Arc<RwLock<JobC
|
||||||
|
|
||||||
let job_container_rescan = job_container.clone();
|
let job_container_rescan = job_container.clone();
|
||||||
let result =
|
let result =
|
||||||
actix_web::web::block(move || _rescan_vault(db, job_container_rescan, job_id)).await;
|
actix_web::web::block(move || _rescan_vault(db, job_container_rescan, job_id, initial))
|
||||||
|
.await;
|
||||||
|
|
||||||
if result.is_err() {
|
if result.is_err() {
|
||||||
let err = result.err().unwrap();
|
let err = result.err().unwrap();
|
||||||
|
@ -99,6 +104,7 @@ fn _rescan_vault<D: Borrow<UpEndDatabase>>(
|
||||||
db: D,
|
db: D,
|
||||||
job_container: Arc<RwLock<JobContainer>>,
|
job_container: Arc<RwLock<JobContainer>>,
|
||||||
job_id: JobId,
|
job_id: JobId,
|
||||||
|
initial: bool,
|
||||||
) -> Result<Vec<UpdatePathOutcome>> {
|
) -> Result<Vec<UpdatePathOutcome>> {
|
||||||
let start = Instant::now();
|
let start = Instant::now();
|
||||||
info!("Vault rescan started.");
|
info!("Vault rescan started.");
|
||||||
|
@ -111,9 +117,12 @@ fn _rescan_vault<D: Borrow<UpEndDatabase>>(
|
||||||
initialize_types(&connection)?;
|
initialize_types(&connection)?;
|
||||||
|
|
||||||
// Disable syncing in SQLite for the duration of the import
|
// Disable syncing in SQLite for the duration of the import
|
||||||
debug!("Disabling SQLite synchronous mode");
|
let mut _guard: Option<PragmaSynchronousGuard> = None;
|
||||||
connection.execute("PRAGMA synchronous = OFF;")?;
|
if initial {
|
||||||
let _guard = PragmaSynchronousGuard(&connection);
|
debug!("Disabling SQLite synchronous mode");
|
||||||
|
connection.execute("PRAGMA synchronous = OFF;")?;
|
||||||
|
_guard = Some(PragmaSynchronousGuard(&connection));
|
||||||
|
}
|
||||||
|
|
||||||
// Walk through the vault, find all paths
|
// Walk through the vault, find all paths
|
||||||
debug!("Traversing vault directory");
|
debug!("Traversing vault directory");
|
||||||
|
@ -418,7 +427,7 @@ mod test {
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
// Initial scan
|
// Initial scan
|
||||||
let rescan_result = _rescan_vault(&open_result.db, job_container.clone(), job_id);
|
let rescan_result = _rescan_vault(&open_result.db, job_container.clone(), job_id, true);
|
||||||
|
|
||||||
assert!(rescan_result.is_ok());
|
assert!(rescan_result.is_ok());
|
||||||
let rescan_result = rescan_result.unwrap();
|
let rescan_result = rescan_result.unwrap();
|
||||||
|
@ -429,7 +438,7 @@ mod test {
|
||||||
|
|
||||||
// Modification-less rescan
|
// Modification-less rescan
|
||||||
|
|
||||||
let rescan_result = _rescan_vault(&open_result.db, job_container.clone(), job_id);
|
let rescan_result = _rescan_vault(&open_result.db, job_container.clone(), job_id, false);
|
||||||
|
|
||||||
assert!(rescan_result.is_ok());
|
assert!(rescan_result.is_ok());
|
||||||
let rescan_result = rescan_result.unwrap();
|
let rescan_result = rescan_result.unwrap();
|
||||||
|
@ -442,7 +451,7 @@ mod test {
|
||||||
|
|
||||||
std::fs::remove_file(temp_dir.path().join("hello-world.txt")).unwrap();
|
std::fs::remove_file(temp_dir.path().join("hello-world.txt")).unwrap();
|
||||||
|
|
||||||
let rescan_result = _rescan_vault(&open_result.db, job_container, job_id);
|
let rescan_result = _rescan_vault(&open_result.db, job_container, job_id, false);
|
||||||
|
|
||||||
assert!(rescan_result.is_ok());
|
assert!(rescan_result.is_ok());
|
||||||
let rescan_result = rescan_result.unwrap();
|
let rescan_result = rescan_result.unwrap();
|
||||||
|
|
|
@ -194,7 +194,7 @@ fn main() -> Result<()> {
|
||||||
|
|
||||||
if !matches.is_present("NO_INITIAL_UPDATE") {
|
if !matches.is_present("NO_INITIAL_UPDATE") {
|
||||||
info!("Running initial update...");
|
info!("Running initial update...");
|
||||||
actix::spawn(filesystem::rescan_vault(upend, job_container));
|
actix::spawn(filesystem::rescan_vault(upend, job_container, true));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "desktop")]
|
#[cfg(feature = "desktop")]
|
||||||
|
|
|
@ -378,6 +378,7 @@ pub async fn api_refresh(state: web::Data<State>) -> Result<HttpResponse, Error>
|
||||||
actix::spawn(crate::filesystem::rescan_vault(
|
actix::spawn(crate::filesystem::rescan_vault(
|
||||||
state.upend.clone(),
|
state.upend.clone(),
|
||||||
state.job_container.clone(),
|
state.job_container.clone(),
|
||||||
|
false,
|
||||||
));
|
));
|
||||||
Ok(HttpResponse::Ok().finish())
|
Ok(HttpResponse::Ok().finish())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue