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
This commit is contained in:
Damien Elmes 2022-09-20 16:12:12 +10:00
parent 52f52724fa
commit 09cb8b3cf6
2 changed files with 6 additions and 15 deletions

View File

@ -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()?;

View File

@ -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,
}