Conversation
setbap
left a comment
There was a problem hiding this comment.
First of all, I want to thank you for your attention and time.
I think there are some problems with this pull request that I tried to specify them. In some parts, it seems that the performance has decreased, also in some parts, the nested codes have reduced the code readability
| fn get_self_info() -> Result<UserProfile, IcpUserError> { | ||
| let caller: String = ic_cdk::api::caller().to_text(); | ||
| let user = _get_profile(caller); | ||
| let user = _get_profile(caller.clone()); |
| if let Some(paste) = _get_paste_by_id(idx) { | ||
| pastes.push(paste); | ||
| } else { |
There was a problem hiding this comment.
this way has more indent and i thinks original way has much cleaner code
| if let Some(paste) = _get_paste_by_id(index) { | ||
| Ok(paste) | ||
| } else { | ||
| Err(IcpPasteError::PasteNotFound) | ||
| } |
There was a problem hiding this comment.
original way is cleaner and more Rusty
| ic_cdk::caller() | ||
| let id = if let Some(caller_id) = caller { | ||
| caller_id | ||
| } else { |
There was a problem hiding this comment.
still i think original way is cleaner and more readable.it has less indent and if works like guard.
| let mut pastes = vec![]; | ||
| let mut ids = vec![]; | ||
| let mut count = if None == count { 10 } else { count.unwrap() } as u64; | ||
| if count > 10 { |
There was a problem hiding this comment.
max count is 10 and seems is was remove in your code
| if let Some(paste_id) = PASTES_SHORT_URL.with(|p| p.borrow().get(&short_url)) { | ||
| if let Some(paste) = _get_paste_by_id(paste_id.to_string()) { | ||
| return Ok(paste); | ||
| } | ||
| } | ||
| let paste = _get_paste_by_id(paste_id.unwrap()); | ||
| paste.ok_or(IcpPasteError::PasteNotFound) | ||
| Err(IcpPasteError::PasteNotFound) |
| return Err(IcpPasteError::PasteIsNotAccessable); | ||
| } | ||
| let paste = _get_paste_by_id(paste_id); | ||
| let paste = _get_paste_by_id(paste_id.clone()); |
|
|
||
| // short url should be unique | ||
| if short_url.is_some() && _is_short_url_exist(&short) { | ||
| if _is_short_url_exist(&short) { |
There was a problem hiding this comment.
this way has performance issue. if url doesn't exist it check for empty string in short.
why we add extra search in blockchain data while we know it is empty
Hey @setbap
This pull request addresses various improvements and fixes in two canisters, namely
userandpaste. The changes aim to enhance code clarity, error handling, and overall maintainability.Changes in
userCanisterRefactored User Profile Logic: Refactored the logic related to user profiles, improving code organization and readability.
Simplified Profile Existence Check: Simplified the check for the existence of a user profile during profile creation, making the code more concise.
Enhanced Error Handling: Improved error handling during user profile updates and creations, providing more informative error messages.
Optimized Paste Index Handling: Optimized the handling of paste indices in user profiles for better performance.
Changes in
pasteCanisterRefactored PasteData Logic: Restructured the logic for managing PasteData, improving code structure and modularity.
Improved Error Messages: Enhanced error messages for paste-related queries and updates, providing clearer information about the encountered issues.
Simplified Code for Finding Pastes: Simplified the code for finding pastes by tags, extension, name, and short URL, making it more readable and maintainable.
Optimized Paste Retrieval: Optimized the retrieval of pastes by user, last N pastes, and other queries for better performance.
General Improvements
Consistent Naming Conventions: Ensured consistent naming conventions throughout the codebase for better code readability.
Enhanced Code Comments: Improved code comments to provide better documentation and understanding of the code.
Fixed Minor Typos: Corrected minor typos in comments and variable names.