BLOG-78 Backend image upload and download #84
Loading…
x
Reference in New Issue
Block a user
No description provided.
Delete Branch "BLOG-78_image_management"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Description
/image/upload
/image/{id}
Package Changes
Screenshots
No response
Reference
Resolves #78
Checklist
/improve
PR Code Suggestions ✨
Avoid unnecessary data cloning
The
to_entity
method currently clones thedata
vector. IfImageRequestDto
is atransient object used solely to create an
Image
entity, it can take ownership of thedata
to avoid an unnecessary deep copy, which can be inefficient for large images.Change the method to consume
self
.backend/feature/image/src/adapter/delivery/image_request_dto.rs [9-14]
Suggestion importance[1-10]: 9
__
Why: This is a significant optimization. By consuming
self
into_entity
, the method avoids unnecessary deep cloning of thedata
vector, which can be large, leading to better performance and more idiomatic Rust.Construct complete objects directly
The current implementation constructs an
Image
entity in two steps: first, anincomplete
Image
with empty data fromImageDbMapper::to_entity
, then mutating itwith data from storage. It's more robust and idiomatic to construct the
Image
objectfully in one step, combining metadata from
image_mapper
and data fromimage_storage
.This also allows removing the problematic
to_entity
method fromImageDbMapper
.backend/feature/image/src/adapter/gateway/image_repository_impl.rs [44-47]
Suggestion importance[1-10]: 8
__
Why: This suggestion improves code clarity and robustness by constructing the
Image
object in a single step, avoiding an intermediate, incomplete state and an unnecessaryVec::new()
allocation. It's a good idiomatic Rust practice.Addressed in
aaf43f21bd
Addressed in
f5c12ce56d