only insert ADDED on first add
parent
3cd3df27c0
commit
dc72b0a34c
|
@ -28,7 +28,7 @@ use diesel::result::{DatabaseErrorKind, Error};
|
|||
use diesel::sqlite::SqliteConnection;
|
||||
use hierarchies::initialize_hier;
|
||||
use log::{debug, trace};
|
||||
use std::convert::TryFrom;
|
||||
use std::convert::{TryFrom, TryInto};
|
||||
use std::fs;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::sync::Arc;
|
||||
|
@ -200,7 +200,7 @@ impl UpEndConnection {
|
|||
.map(|mv| mv.value.clone())
|
||||
}
|
||||
|
||||
pub fn insert_file(&self, file: models::NewFile) -> Result<usize> {
|
||||
pub fn insert_file(&self, file: models::NewFile) -> Result<u32> {
|
||||
use crate::database::inner::schema::files;
|
||||
|
||||
debug!(
|
||||
|
@ -209,9 +209,17 @@ impl UpEndConnection {
|
|||
Address::Hash(Hash((&file.hash).clone()))
|
||||
);
|
||||
|
||||
Ok(diesel::insert_into(files::table)
|
||||
.values(file)
|
||||
.execute(&self.conn)?)
|
||||
diesel::insert_into(files::table)
|
||||
.values(&file)
|
||||
.execute(&self.conn)?;
|
||||
|
||||
Ok(files::dsl::files
|
||||
.filter(files::dsl::valid.eq(true))
|
||||
.filter(files::dsl::hash.eq(file.hash))
|
||||
.count()
|
||||
.first::<i64>(&self.conn)?
|
||||
.try_into()
|
||||
.unwrap())
|
||||
}
|
||||
|
||||
pub fn retrieve_file(&self, obj_hash: Hash) -> Result<Vec<models::OutFile>> {
|
||||
|
|
|
@ -440,11 +440,13 @@ fn insert_file_with_metadata(
|
|||
|
||||
// Insert all
|
||||
connection.transaction::<_, Error, _>(|| {
|
||||
connection.insert_file(new_file)?;
|
||||
let file_count = connection.insert_file(new_file)?;
|
||||
|
||||
connection.insert_entry_immutable(type_entry)?;
|
||||
connection.insert_entry_immutable(size_entry)?;
|
||||
connection.insert_entry_immutable(added_entry)?;
|
||||
if file_count == 1 {
|
||||
connection.insert_entry_immutable(added_entry)?;
|
||||
}
|
||||
if let Some(mime_entry) = mime_entry {
|
||||
connection.insert_entry(mime_entry)?;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue