job parent id fix (#714)

This commit is contained in:
Brendan Allan authored and GitHub committed 2023-04-17 10:26:27 -07:00
1 parent ec900dcc9d
commit 98d846827d
3 files changed
+51 -34

No files matched your search

+11 -6
View File
@@ -17,6 +17,7 @@ use crate::{
validation::validator_job::ObjectValidatorJob,
},
prisma::{job, node},
util,
};
use std::{
@@ -455,12 +456,16 @@ impl JobReport {
self.name.clone(),
JobStatus::Running as i32,
node::id::equals(library.node_local_id),
vec![
job::data::set(self.data.clone()),
job::parent_id::set(self.parent_id.map(|id| id.as_bytes().to_vec())),
job::date_created::set(now.into()),
job::date_modified::set(now.into()),
],
util::db::chain_optional_iter(
[
job::data::set(self.data.clone()),
job::date_created::set(now.into()),
job::date_modified::set(now.into()),
],
[self
.parent_id
.map(|id| job::parent::connect(job::id::equals(id.as_bytes().to_vec())))],
),
)
.exec()
.await?;
+26 -28
View File
@@ -330,7 +330,7 @@ impl LastFilePathIdManager {
) -> Result<file_path::Data, FilePathError> {
// Keeping a reference in that map for the entire duration of the function, so we keep it locked
use crate::sync;
use crate::{sync, util};
use serde_json::json;
let mut last_id_ref = match self.last_id_by_location.entry(location_id) {
@@ -351,33 +351,31 @@ impl LastFilePathIdManager {
let next_id = *last_id_ref + 1;
let params = [
("cas_id", json!(cas_id)),
("materialized_path", json!(materialized_path)),
("name", json!(name)),
("extension", json!(extension)),
("size_in_bytes", json!(metadata.size_in_bytes.to_string())),
("inode", json!(metadata.inode.to_le_bytes())),
("device", json!(metadata.device.to_le_bytes())),
("is_dir", json!(is_dir)),
("date_created", json!(metadata.created_at)),
("date_modified", json!(metadata.modified_at)),
]
.into_iter()
.map(Some)
.chain([parent_id.map(|parent_id| {
(
"parent_id",
json!(sync::file_path::SyncId {
location: sync::location::SyncId {
pub_id: location.pub_id.clone()
},
id: parent_id
}),
)
})])
.flatten()
.collect::<Vec<_>>();
let params = util::db::chain_optional_iter(
[
("cas_id", json!(cas_id)),
("materialized_path", json!(materialized_path)),
("name", json!(name)),
("extension", json!(extension)),
("size_in_bytes", json!(metadata.size_in_bytes.to_string())),
("inode", json!(metadata.inode.to_le_bytes())),
("device", json!(metadata.device.to_le_bytes())),
("is_dir", json!(is_dir)),
("date_created", json!(metadata.created_at)),
("date_modified", json!(metadata.modified_at)),
],
[parent_id.map(|parent_id| {
(
"parent_id",
json!(sync::file_path::SyncId {
location: sync::location::SyncId {
pub_id: location.pub_id.clone()
},
id: parent_id
}),
)
})],
);
let created_path = sync
.write_op(
+14
View File
@@ -71,3 +71,17 @@ pub async fn write_storedkey_to_db(
Ok(())
}
/// Combines an iterator of `T` and an iterator of `Option<T>`,
/// removing any `None` values in the process
pub fn chain_optional_iter<T>(
required: impl IntoIterator<Item = T>,
optional: impl IntoIterator<Item = Option<T>>,
) -> Vec<T> {
required
.into_iter()
.map(Some)
.chain(optional)
.flatten()
.collect()
}