Fix tagging file with new tag
When tagging a file with a brand new tag, we were using the number of rows affected as the ID instead of doing the query for the ID of the row we just inserted, this should fix when we tag a photo with a new tag.
This commit is contained in:
25
src/tags.rs
25
src/tags.rs
@@ -185,7 +185,7 @@ pub struct SqliteTagDao {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl SqliteTagDao {
|
impl SqliteTagDao {
|
||||||
fn new(connection: SqliteConnection) -> Self {
|
pub(crate) fn new(connection: SqliteConnection) -> Self {
|
||||||
SqliteTagDao { connection }
|
SqliteTagDao { connection }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -235,8 +235,7 @@ impl TagDao for SqliteTagDao {
|
|||||||
.and_then(|id| {
|
.and_then(|id| {
|
||||||
debug!("Got id: {:?} for inserted tag: {:?}", id, name);
|
debug!("Got id: {:?} for inserted tag: {:?}", id, name);
|
||||||
tags::table
|
tags::table
|
||||||
.left_join(tagged_photo::table)
|
.filter(tags::id.eq(id))
|
||||||
.filter(tagged_photo::id.eq(id))
|
|
||||||
.select((tags::id, tags::name, tags::created_time))
|
.select((tags::id, tags::name, tags::created_time))
|
||||||
.get_result::<Tag>(self.connection.borrow_mut())
|
.get_result::<Tag>(self.connection.borrow_mut())
|
||||||
.with_context(|| "Unable to get tagged photo from Sqlite")
|
.with_context(|| "Unable to get tagged photo from Sqlite")
|
||||||
@@ -274,13 +273,29 @@ impl TagDao for SqliteTagDao {
|
|||||||
created_time: Utc::now().timestamp(),
|
created_time: Utc::now().timestamp(),
|
||||||
})
|
})
|
||||||
.execute(self.connection.borrow_mut())
|
.execute(self.connection.borrow_mut())
|
||||||
.with_context(|| "Unable to tag file in sqlite")
|
.with_context(|| format!("Unable to tag file {:?} in sqlite", path))
|
||||||
|
.and_then(|_| {
|
||||||
|
debug!("Inserted tagged photo: {:#} -> {:?}", tag_id, path);
|
||||||
|
no_arg_sql_function!(
|
||||||
|
last_insert_rowid,
|
||||||
|
diesel::sql_types::Integer,
|
||||||
|
"Represents the SQL last_insert_row() function"
|
||||||
|
);
|
||||||
|
diesel::select(last_insert_rowid)
|
||||||
|
.get_result::<i32>(&mut self.connection)
|
||||||
|
.with_context(|| "Unable to get last inserted tag from Sqlite")
|
||||||
|
})
|
||||||
.and_then(|tagged_id| {
|
.and_then(|tagged_id| {
|
||||||
debug!("Inserted tagged photo: {:?}", tagged_id);
|
debug!("Inserted tagged photo: {:?}", tagged_id);
|
||||||
tagged_photo::table
|
tagged_photo::table
|
||||||
.find(tagged_id as i32)
|
.find(tagged_id as i32)
|
||||||
.first(self.connection.borrow_mut())
|
.first(self.connection.borrow_mut())
|
||||||
.with_context(|| "Error getting inserted tagged photo")
|
.with_context(|| {
|
||||||
|
format!(
|
||||||
|
"Error getting inserted tagged photo with id: {:?}",
|
||||||
|
tagged_id
|
||||||
|
)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user