Feat/version2.0 feature merges#97
Conversation
# Conflicts: # Cargo.lock # Cargo.toml # src/database/dsls/object_dsl.rs # src/grpc/collections.rs # src/grpc/datasets.rs # src/grpc/notification.rs # src/grpc/relations.rs # tests/setup.sh
…ections and Datasets.
# Conflicts: # src/grpc/collections.rs
St4NNi
left a comment
There was a problem hiding this comment.
Good work, one thing i really do not like is iterating over DB requests. We should add get / update requests that take a list and process them all at once.
| Vec<InternalRelation>, // outbound relations | ||
| Vec<InternalRelation>, // inbound relations | ||
| )> { | ||
| let outbound = "SELECT * FROM internal_relations |
There was a problem hiding this comment.
not a fan, we should combine outbound and inbound to one request:
`SELECT * FROM internal_relations WHERE target_pid = $1 OR origin_pid = $1;
And separate the afterwards, especially since you are iterating over them anyway.
Iterator::partition can be used to get two vectors.
| "Internal database error" | ||
| ); | ||
|
|
||
| for o in updates { |
There was a problem hiding this comment.
Not a fan either, would prefer updating them all at once, with one db request.
| self.database_handler.snapshot(request).await, | ||
| "Internal database error." | ||
| ); | ||
| for resource in &resources { |
There was a problem hiding this comment.
Again, for loop for updating sounds not like a good idea.
| "Internal database error" | ||
| ); | ||
|
|
||
| for o in updates { |
| "Internal database error" | ||
| ); | ||
|
|
||
| for o in updates { |
There was a problem hiding this comment.
Again updating them all separately is a bad idea
| .remove_external_relation(&transaction_client, external_to_remove) | ||
| .await?; | ||
| } | ||
| for internal_to_remove in labels_to_remove.internal { |
| client: &Client, | ||
| ) -> Result<Vec<ObjectWithRelations>> { | ||
| let mut result: Vec<ObjectWithRelations> = Vec::new(); | ||
| for relation in &project.relation_ids { |
| for relation in &project.relation_ids { | ||
| InternalRelation::archive(relation, client).await?; | ||
| } | ||
| for resource in &project.resource_ids { |
| } | ||
| for resource in &project.resource_ids { | ||
| Object::archive(resource, client).await?; | ||
| result.push(Object::get_object_with_relations(resource, client).await?); |
There was a problem hiding this comment.
updating AND retrieving with two requests in a for loop is really bad
| let (mut ids, mut init_in) = InternalRelation::get_all_by_id(project_id, client).await?; | ||
| ids.append(&mut init_in); | ||
| for id in ids.iter().map(|i| i.id) { | ||
| let (outs, ins) = InternalRelation::get_all_by_id(id, client).await?; |
das-Abroxas
left a comment
There was a problem hiding this comment.
Some copy & paste things that should be smoothed out before merge.
| let collection_id = tonic_invalid!(request.get_id(), "Invalid project id"); | ||
| let ctx = Context::res_ctx(collection_id, DbPermissionLevel::WRITE, true); | ||
|
|
||
| tonic_auth!( | ||
| self.authorizer.check_permissions(&token, vec![ctx]).await, | ||
| "Unauthorized" | ||
| ); | ||
|
|
||
| let project = tonic_internal!( | ||
| self.database_handler.update_name(request).await, | ||
| "Internal database error." | ||
| ); | ||
| self.cache | ||
| .update_object(&project.object.id, project.clone()); | ||
| let project: generic_resource::Resource = | ||
| tonic_internal!(project.try_into(), "Collection conversion error"); |
There was a problem hiding this comment.
Copy & paste only partially adapted.
| let collection_id = tonic_invalid!(request.get_id(), "Invalid project id"); | |
| let ctx = Context::res_ctx(collection_id, DbPermissionLevel::WRITE, true); | |
| tonic_auth!( | |
| self.authorizer.check_permissions(&token, vec![ctx]).await, | |
| "Unauthorized" | |
| ); | |
| let project = tonic_internal!( | |
| self.database_handler.update_name(request).await, | |
| "Internal database error." | |
| ); | |
| self.cache | |
| .update_object(&project.object.id, project.clone()); | |
| let project: generic_resource::Resource = | |
| tonic_internal!(project.try_into(), "Collection conversion error"); | |
| let project_id = tonic_invalid!(request.get_id(), "Invalid project id"); | |
| let ctx = Context::res_ctx(project_id, DbPermissionLevel::WRITE, true); | |
| tonic_auth!( | |
| self.authorizer.check_permissions(&token, vec![ctx]).await, | |
| "Unauthorized" | |
| ); | |
| let project = tonic_internal!( | |
| self.database_handler.update_name(request).await, | |
| "Internal database error." | |
| ); | |
| self.cache | |
| .update_object(&project.object.id, project.clone()); | |
| let project: generic_resource::Resource = | |
| tonic_internal!(project.try_into(), "Project conversion error"); |
| let request = DescriptionUpdate::Project(request.into_inner()); | ||
| let collection_id = tonic_invalid!(request.get_id(), "Invalid project id"); | ||
| let ctx = Context::res_ctx(collection_id, DbPermissionLevel::WRITE, true); | ||
|
|
||
| tonic_auth!( | ||
| self.authorizer.check_permissions(&token, vec![ctx]).await, | ||
| "Unauthorized" | ||
| ); | ||
|
|
||
| let project = tonic_internal!( | ||
| self.database_handler.update_description(request).await, | ||
| "Internal database error." | ||
| ); | ||
| self.cache | ||
| .update_object(&project.object.id, project.clone()); | ||
| let project: generic_resource::Resource = | ||
| tonic_internal!(project.try_into(), "Collection conversion error"); |
There was a problem hiding this comment.
Copy & paste only partially adapted.
| let request = DescriptionUpdate::Project(request.into_inner()); | |
| let collection_id = tonic_invalid!(request.get_id(), "Invalid project id"); | |
| let ctx = Context::res_ctx(collection_id, DbPermissionLevel::WRITE, true); | |
| tonic_auth!( | |
| self.authorizer.check_permissions(&token, vec![ctx]).await, | |
| "Unauthorized" | |
| ); | |
| let project = tonic_internal!( | |
| self.database_handler.update_description(request).await, | |
| "Internal database error." | |
| ); | |
| self.cache | |
| .update_object(&project.object.id, project.clone()); | |
| let project: generic_resource::Resource = | |
| tonic_internal!(project.try_into(), "Collection conversion error"); | |
| let request = DescriptionUpdate::Project(request.into_inner()); | |
| let project_id = tonic_invalid!(request.get_id(), "Invalid project id"); | |
| let ctx = Context::res_ctx(project_id, DbPermissionLevel::WRITE, true); | |
| tonic_auth!( | |
| self.authorizer.check_permissions(&token, vec![ctx]).await, | |
| "Unauthorized" | |
| ); | |
| let project = tonic_internal!( | |
| self.database_handler.update_description(request).await, | |
| "Internal database error." | |
| ); | |
| self.cache | |
| .update_object(&project.object.id, project.clone()); | |
| let project: generic_resource::Resource = | |
| tonic_internal!(project.try_into(), "Project conversion error"); |
| let collection_id = tonic_invalid!(request.get_id(), "Invalid project id"); | ||
| let ctx = Context::res_ctx(collection_id, DbPermissionLevel::WRITE, true); | ||
|
|
||
| tonic_auth!( | ||
| self.authorizer.check_permissions(&token, vec![ctx]).await, | ||
| "Unauthorized" | ||
| ); | ||
|
|
||
| let project = tonic_internal!( | ||
| self.database_handler.update_keyvals(request).await, | ||
| "Internal database error." | ||
| ); | ||
| self.cache | ||
| .update_object(&project.object.id, project.clone()); | ||
| let project: generic_resource::Resource = | ||
| tonic_internal!(project.try_into(), "Collection conversion error"); |
There was a problem hiding this comment.
Copy & paste only partially adapted.
| let collection_id = tonic_invalid!(request.get_id(), "Invalid project id"); | |
| let ctx = Context::res_ctx(collection_id, DbPermissionLevel::WRITE, true); | |
| tonic_auth!( | |
| self.authorizer.check_permissions(&token, vec![ctx]).await, | |
| "Unauthorized" | |
| ); | |
| let project = tonic_internal!( | |
| self.database_handler.update_keyvals(request).await, | |
| "Internal database error." | |
| ); | |
| self.cache | |
| .update_object(&project.object.id, project.clone()); | |
| let project: generic_resource::Resource = | |
| tonic_internal!(project.try_into(), "Collection conversion error"); | |
| let project_id = tonic_invalid!(request.get_id(), "Invalid project id"); | |
| let ctx = Context::res_ctx(project_id, DbPermissionLevel::WRITE, true); | |
| tonic_auth!( | |
| self.authorizer.check_permissions(&token, vec![ctx]).await, | |
| "Unauthorized" | |
| ); | |
| let project = tonic_internal!( | |
| self.database_handler.update_keyvals(request).await, | |
| "Internal database error." | |
| ); | |
| self.cache | |
| .update_object(&project.object.id, project.clone()); | |
| let project: generic_resource::Resource = | |
| tonic_internal!(project.try_into(), "Project conversion error"); |
| let collection_id = tonic_invalid!(request.get_id(), "Invalid project id"); | ||
| let ctx = Context::res_ctx(collection_id, DbPermissionLevel::WRITE, true); | ||
|
|
||
| tonic_auth!( | ||
| self.authorizer.check_permissions(&token, vec![ctx]).await, | ||
| "Unauthorized" | ||
| ); | ||
|
|
||
| let project = tonic_internal!( | ||
| self.database_handler.update_dataclass(request).await, | ||
| "Internal database error." | ||
| ); | ||
| self.cache | ||
| .update_object(&project.object.id, project.clone()); | ||
| let project: generic_resource::Resource = | ||
| tonic_internal!(project.try_into(), "Collection conversion error"); |
There was a problem hiding this comment.
Copy & paste only partially adapted.
| let collection_id = tonic_invalid!(request.get_id(), "Invalid project id"); | |
| let ctx = Context::res_ctx(collection_id, DbPermissionLevel::WRITE, true); | |
| tonic_auth!( | |
| self.authorizer.check_permissions(&token, vec![ctx]).await, | |
| "Unauthorized" | |
| ); | |
| let project = tonic_internal!( | |
| self.database_handler.update_dataclass(request).await, | |
| "Internal database error." | |
| ); | |
| self.cache | |
| .update_object(&project.object.id, project.clone()); | |
| let project: generic_resource::Resource = | |
| tonic_internal!(project.try_into(), "Collection conversion error"); | |
| let project_id = tonic_invalid!(request.get_id(), "Invalid project id"); | |
| let ctx = Context::res_ctx(project_id, DbPermissionLevel::WRITE, true); | |
| tonic_auth!( | |
| self.authorizer.check_permissions(&token, vec![ctx]).await, | |
| "Unauthorized" | |
| ); | |
| let project = tonic_internal!( | |
| self.database_handler.update_dataclass(request).await, | |
| "Internal database error." | |
| ); | |
| self.cache | |
| .update_object(&project.object.id, project.clone()); | |
| let project: generic_resource::Resource = | |
| tonic_internal!(project.try_into(), "Project conversion error"); |
| let project_id = tonic_invalid!(request.get_id(), "Invalid dataset id."); | ||
| let ctx = Context::res_ctx(project_id, DbPermissionLevel::ADMIN, true); | ||
|
|
||
| tonic_auth!( | ||
| self.authorizer.check_permissions(&token, vec![ctx]).await, | ||
| "Unauthorized" | ||
| ); | ||
|
|
||
| // this only contains one entry with a dataset | ||
| let resources = tonic_internal!( | ||
| self.database_handler.snapshot(request).await, | ||
| "Internal database error." | ||
| ); | ||
| for resource in &resources { | ||
| self.cache | ||
| .update_object(&resource.object.id, resource.clone()); | ||
| } | ||
| let project: generic_resource::Resource = | ||
| // First entry is always the archived project | ||
| tonic_internal!(resources[0].clone().try_into(), "Dataset conversion error"); |
There was a problem hiding this comment.
Copy & paste only partially adapted.
| let project_id = tonic_invalid!(request.get_id(), "Invalid dataset id."); | |
| let ctx = Context::res_ctx(project_id, DbPermissionLevel::ADMIN, true); | |
| tonic_auth!( | |
| self.authorizer.check_permissions(&token, vec![ctx]).await, | |
| "Unauthorized" | |
| ); | |
| // this only contains one entry with a dataset | |
| let resources = tonic_internal!( | |
| self.database_handler.snapshot(request).await, | |
| "Internal database error." | |
| ); | |
| for resource in &resources { | |
| self.cache | |
| .update_object(&resource.object.id, resource.clone()); | |
| } | |
| let project: generic_resource::Resource = | |
| // First entry is always the archived project | |
| tonic_internal!(resources[0].clone().try_into(), "Dataset conversion error"); | |
| let project_id = tonic_invalid!(request.get_id(), "Invalid project id"); | |
| let ctx = Context::res_ctx(project_id, DbPermissionLevel::ADMIN, true); | |
| tonic_auth!( | |
| self.authorizer.check_permissions(&token, vec![ctx]).await, | |
| "Unauthorized" | |
| ); | |
| // This contains all the resources the snapshot includes below the project | |
| let resources = tonic_internal!( | |
| self.database_handler.snapshot(request).await, | |
| "Internal database error." | |
| ); | |
| for resource in &resources { | |
| self.cache | |
| .update_object(&resource.object.id, resource.clone()); | |
| } | |
| let project: generic_resource::Resource = | |
| // First entry is always the archived project | |
| tonic_internal!(resources[0].clone().try_into(), "Project conversion error"); |
| let collection_id = tonic_invalid!(request.get_id(), "Invalid dataset id."); | ||
| let ctx = Context::res_ctx(collection_id, DbPermissionLevel::ADMIN, true); | ||
|
|
||
| tonic_auth!( | ||
| self.authorizer.check_permissions(&token, vec![ctx]).await, | ||
| "Unauthorized" | ||
| ); | ||
|
|
||
| // this only contains one entry with a dataset | ||
| let resources = tonic_internal!( | ||
| self.database_handler.snapshot(request).await, | ||
| "Internal database error." | ||
| ); | ||
| for resource in &resources { | ||
| self.cache | ||
| .update_object(&resource.object.id, resource.clone()); | ||
| } | ||
| let collection: generic_resource::Resource = | ||
| // First entry is always the snapshot collection | ||
| tonic_internal!(resources[0].clone().try_into(), "Dataset conversion error"); |
There was a problem hiding this comment.
Copy & paste only partially adapted.
| let collection_id = tonic_invalid!(request.get_id(), "Invalid dataset id."); | |
| let ctx = Context::res_ctx(collection_id, DbPermissionLevel::ADMIN, true); | |
| tonic_auth!( | |
| self.authorizer.check_permissions(&token, vec![ctx]).await, | |
| "Unauthorized" | |
| ); | |
| // this only contains one entry with a dataset | |
| let resources = tonic_internal!( | |
| self.database_handler.snapshot(request).await, | |
| "Internal database error." | |
| ); | |
| for resource in &resources { | |
| self.cache | |
| .update_object(&resource.object.id, resource.clone()); | |
| } | |
| let collection: generic_resource::Resource = | |
| // First entry is always the snapshot collection | |
| tonic_internal!(resources[0].clone().try_into(), "Dataset conversion error"); | |
| let collection_id = tonic_invalid!(request.get_id(), "Invalid collection id."); | |
| let ctx = Context::res_ctx(collection_id, DbPermissionLevel::ADMIN, true); | |
| tonic_auth!( | |
| self.authorizer.check_permissions(&token, vec![ctx]).await, | |
| "Unauthorized" | |
| ); | |
| // This contains all resources the snapshot includes below the collection | |
| let resources = tonic_internal!( | |
| self.database_handler.snapshot(request).await, | |
| "Internal database error." | |
| ); | |
| for resource in &resources { | |
| self.cache | |
| .update_object(&resource.object.id, resource.clone()); | |
| } | |
| let collection: generic_resource::Resource = | |
| // First entry is always the snapshot collection | |
| tonic_internal!(resources[0].clone().try_into(), "Collection conversion error"); |
Codecov ReportPatch coverage:
Additional details and impacted files@@ Coverage Diff @@
## feat/version2.0rework #97 +/- ##
=========================================================
+ Coverage 17.96% 21.23% +3.26%
=========================================================
Files 36 43 +7
Lines 3022 3758 +736
=========================================================
+ Hits 543 798 +255
- Misses 2479 2960 +481
☔ View full report in Codecov by Sentry. |
St4NNi
left a comment
There was a problem hiding this comment.
Nice, additions for now LGTM. This will surely be modified in further developments.
Summary
This PR contains delete, relations and archive requests.
Delete
object_status = DELETEDRelations
ModifyRelationsis now implementedArchive/Snapshot
dynamic = false