only disable sqlite synchronous mode on initial update
parent
ecaea693c6
commit
a91711adc8
|
@ -48,7 +48,11 @@ fn initialize_types(connection: &UpEndConnection) -> Result<()> {
|
|||
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
|
||||
.write()
|
||||
.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 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() {
|
||||
let err = result.err().unwrap();
|
||||
|
@ -99,6 +104,7 @@ fn _rescan_vault<D: Borrow<UpEndDatabase>>(
|
|||
db: D,
|
||||
job_container: Arc<RwLock<JobContainer>>,
|
||||
job_id: JobId,
|
||||
initial: bool,
|
||||
) -> Result<Vec<UpdatePathOutcome>> {
|
||||
let start = Instant::now();
|
||||
info!("Vault rescan started.");
|
||||
|
@ -111,9 +117,12 @@ fn _rescan_vault<D: Borrow<UpEndDatabase>>(
|
|||
initialize_types(&connection)?;
|
||||
|
||||
// Disable syncing in SQLite for the duration of the import
|
||||
debug!("Disabling SQLite synchronous mode");
|
||||
connection.execute("PRAGMA synchronous = OFF;")?;
|
||||
let _guard = PragmaSynchronousGuard(&connection);
|
||||
let mut _guard: Option<PragmaSynchronousGuard> = None;
|
||||
if initial {
|
||||
debug!("Disabling SQLite synchronous mode");
|
||||
connection.execute("PRAGMA synchronous = OFF;")?;
|
||||
_guard = Some(PragmaSynchronousGuard(&connection));
|
||||
}
|
||||
|
||||
// Walk through the vault, find all paths
|
||||
debug!("Traversing vault directory");
|
||||
|
@ -418,7 +427,7 @@ mod test {
|
|||
.unwrap();
|
||||
|
||||
// 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());
|
||||
let rescan_result = rescan_result.unwrap();
|
||||
|
@ -429,7 +438,7 @@ mod test {
|
|||
|
||||
// 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());
|
||||
let rescan_result = rescan_result.unwrap();
|
||||
|
@ -442,7 +451,7 @@ mod test {
|
|||
|
||||
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());
|
||||
let rescan_result = rescan_result.unwrap();
|
||||
|
|
|
@ -194,7 +194,7 @@ fn main() -> Result<()> {
|
|||
|
||||
if !matches.is_present("NO_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")]
|
||||
|
|
|
@ -378,6 +378,7 @@ pub async fn api_refresh(state: web::Data<State>) -> Result<HttpResponse, Error>
|
|||
actix::spawn(crate::filesystem::rescan_vault(
|
||||
state.upend.clone(),
|
||||
state.job_container.clone(),
|
||||
false,
|
||||
));
|
||||
Ok(HttpResponse::Ok().finish())
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue