Redirect manual date edits on a version path to its original (#194)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
0e1fdd43e5
commit
51600f900d
3 files changed
+129
-2
No files matched your search
@@ -188,6 +188,15 @@ pub trait VersionDao: Sync + Send {
|
||||
/// the original's rel_path (same library when possible).
|
||||
fn original_path_of(&mut self, rel_path: &str) -> Result<Option<String>, DbError>;
|
||||
|
||||
/// `(library_id, rel_path)` of the original of the version at
|
||||
/// `(library_id, rel_path)`, when it is a linked version with a live
|
||||
/// original. For per-library writes that must land on the original.
|
||||
fn original_location_of(
|
||||
&mut self,
|
||||
library_id: i32,
|
||||
rel_path: &str,
|
||||
) -> Result<Option<(i32, String)>, DbError>;
|
||||
|
||||
/// Which of `hashes` are versions of something.
|
||||
fn version_hashes_among(&mut self, hashes: &[String]) -> Result<HashSet<String>, DbError>;
|
||||
|
||||
@@ -304,13 +313,25 @@ pub fn canonical_rel_path(
|
||||
library_id: Option<i32>,
|
||||
rel_path: &str,
|
||||
) -> QueryResult<Option<String>> {
|
||||
Ok(canonical_location(conn, library_id, rel_path)?.map(|(_, p)| p))
|
||||
}
|
||||
|
||||
/// [`canonical_rel_path`] with the original's library too, for callers that
|
||||
/// write per-library rows (the manual date lives on the `image_exif` row).
|
||||
pub fn canonical_location(
|
||||
conn: &mut SqliteConnection,
|
||||
library_id: Option<i32>,
|
||||
rel_path: &str,
|
||||
) -> QueryResult<Option<(i32, String)>> {
|
||||
#[derive(QueryableByName)]
|
||||
struct Row {
|
||||
#[diesel(sql_type = Integer)]
|
||||
library_id: i32,
|
||||
#[diesel(sql_type = Text)]
|
||||
rel_path: String,
|
||||
}
|
||||
let rows = sql_query(
|
||||
"SELECT o.rel_path AS rel_path FROM image_exif v \
|
||||
"SELECT o.library_id AS library_id, o.rel_path AS rel_path FROM image_exif v \
|
||||
JOIN photo_versions pv ON pv.version_hash = v.content_hash \
|
||||
JOIN image_exif o ON o.content_hash = pv.original_hash \
|
||||
WHERE v.rel_path = ?1 AND (?2 IS NULL OR v.library_id = ?2) \
|
||||
@@ -323,7 +344,7 @@ pub fn canonical_rel_path(
|
||||
.bind::<Text, _>(rel_path)
|
||||
.bind::<Nullable<Integer>, _>(library_id)
|
||||
.load::<Row>(conn)?;
|
||||
Ok(rows.into_iter().next().map(|r| r.rel_path))
|
||||
Ok(rows.into_iter().next().map(|r| (r.library_id, r.rel_path)))
|
||||
}
|
||||
|
||||
/// Fold favorites and tags recorded on a version's own path into its
|
||||
@@ -522,6 +543,19 @@ impl VersionDao for SqliteVersionDao {
|
||||
.map_err(|e| DbError::log(DbErrorKind::QueryError, e))
|
||||
}
|
||||
|
||||
fn original_location_of(
|
||||
&mut self,
|
||||
library_id: i32,
|
||||
rel_path: &str,
|
||||
) -> Result<Option<(i32, String)>, DbError> {
|
||||
trace_db_call("query", "original_location_of", |_span| {
|
||||
let mut conn = self.connection.lock().expect("Unable to get VersionDao");
|
||||
canonical_location(&mut conn, Some(library_id), rel_path)
|
||||
.map_err(|e| anyhow::anyhow!("Query error: {}", e))
|
||||
})
|
||||
.map_err(|e| DbError::log(DbErrorKind::QueryError, e))
|
||||
}
|
||||
|
||||
fn version_hashes_among(&mut self, hashes: &[String]) -> Result<HashSet<String>, DbError> {
|
||||
trace_db_call("query", "version_hashes_among", |_span| {
|
||||
#[derive(QueryableByName)]
|
||||
|
||||
Reference in new issue
Block a user