From 09cb8b3cf6d9a5faa18880903e36c37cb67d4647 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Tue, 20 Sep 2022 16:12:12 +1000 Subject: [PATCH] Always scan for media changes The check runs in the background, and the dentry cache and SQLite page cache should make this more efficient after the first run. Closes #1736 --- rslib/src/media/changetracker.rs | 17 ++--------------- rslib/src/media/database.rs | 4 ++++ 2 files changed, 6 insertions(+), 15 deletions(-) diff --git a/rslib/src/media/changetracker.rs b/rslib/src/media/changetracker.rs index dcf04da85..d89dd56c0 100644 --- a/rslib/src/media/changetracker.rs +++ b/rslib/src/media/changetracker.rs @@ -8,8 +8,7 @@ use crate::{ media::{ database::{MediaDatabaseContext, MediaEntry}, files::{ - filename_if_normalized, mtime_as_i64, sha1_of_file, MEDIA_SYNC_FILESIZE_LIMIT, - NONSYNCABLE_FILENAME, + filename_if_normalized, sha1_of_file, MEDIA_SYNC_FILESIZE_LIMIT, NONSYNCABLE_FILENAME, }, }, prelude::*, @@ -59,17 +58,7 @@ where pub(super) fn register_changes(&mut self, ctx: &mut MediaDatabaseContext) -> Result<()> { ctx.transact(|ctx| { - // folder mtime unchanged? - let dirmod = mtime_as_i64(self.media_folder)?; - - let mut meta = ctx.get_meta()?; - debug!(self.log, "begin change check"; "folder_mod" => dirmod, "db_mod" => meta.folder_mtime); - if dirmod == meta.folder_mtime { - debug!(self.log, "skip check"); - return Ok(()); - } else { - meta.folder_mtime = dirmod; - } + debug!(self.log, "begin change check"); let mtimes = ctx.all_mtimes()?; self.checked += mtimes.len(); @@ -80,8 +69,6 @@ where self.add_updated_entries(ctx, changed)?; self.remove_deleted_files(ctx, removed)?; - ctx.set_meta(&meta)?; - // unconditional fire at end of op for accurate counts self.fire_progress_cb()?; diff --git a/rslib/src/media/database.rs b/rslib/src/media/database.rs index 927c1e6fd..66b9cf147 100644 --- a/rslib/src/media/database.rs +++ b/rslib/src/media/database.rs @@ -56,6 +56,10 @@ pub struct MediaEntry { #[derive(Debug, PartialEq)] pub struct MediaDatabaseMetadata { + /// The syncing code no longer uses this; files are scanned for + /// indiscriminately. After this has been in production for a while + /// without reports of speed regressions, we should remove the rest + /// of the code that refers to this. pub folder_mtime: i64, pub last_sync_usn: i32, }