Revert "Always scan for media changes"

This reverts commit 09cb8b3cf6.

Overhead on larger folders/slower devices is more than I originally
anticipated, and can run into multiple seconds. This seems to be
particularly egregious on mobile, which I presume is due to sandboxing
overhead.
This commit is contained in:
Damien Elmes 2022-12-15 19:55:40 +10:00
parent 2ccc8ca436
commit 35cbde65d7
2 changed files with 15 additions and 6 deletions

View File

@ -9,7 +9,8 @@ use crate::{
media::{
database::{MediaDatabaseContext, MediaEntry},
files::{
filename_if_normalized, sha1_of_file, MEDIA_SYNC_FILESIZE_LIMIT, NONSYNCABLE_FILENAME,
filename_if_normalized, mtime_as_i64, sha1_of_file, MEDIA_SYNC_FILESIZE_LIMIT,
NONSYNCABLE_FILENAME,
},
},
prelude::*,
@ -59,7 +60,17 @@ where
pub(super) fn register_changes(&mut self, ctx: &mut MediaDatabaseContext) -> Result<()> {
ctx.transact(|ctx| {
debug!(self.log, "begin change check");
// 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;
}
let mtimes = ctx.all_mtimes()?;
self.checked += mtimes.len();
@ -70,6 +81,8 @@ 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()?;

View File

@ -56,10 +56,6 @@ pub struct MediaEntry {
#[derive(Debug, PartialEq, Eq)]
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,
}