Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update paste.rs #2

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Conversation

Muhindo-Galien
Copy link

Hello @setbap

This pull request addresses various improvements and fixes in two canisters, namely lib and paste. The changes aim to enhance code clarity, error handling, and overall maintainability.

  1. Optimized Paste Index Handling: Optimized the handling of paste indices in user profiles for better performance.

Changes in paste Canister

  1. Refactored PasteData Logic: Restructured the logic for managing PasteData, improving code structure and modularity.

  2. Improved Error Messages: Enhanced error messages for paste-related queries and updates, providing clearer information about the encountered issues.

  3. Simplified Code for Finding Pastes: Simplified the code for finding pastes by tags, extension, name, and short URL, making it more readable and maintainable.

  4. Optimized Paste Retrieval: Optimized the retrieval of pastes by user, last N pastes, and other queries for better performance.

General Improvements

  1. Consistent Naming Conventions: Ensured consistent naming conventions throughout the codebase for better code readability.

  2. Enhanced Code Comments: Improved code comments to provide better documentation and understanding of the code.

  3. Fixed Minor Typos: Corrected minor typos in comments and variable names.

Copy link
Owner

@setbap setbap left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your attention and time. I believe this code serves educational purposes, and it would be beneficial to include comments. I understand that for production-grade code, this may slightly reduce code readability. so i prefer to don't remove this comments.

@@ -4,15 +4,15 @@ use serde::{Deserialize, Serialize};
use std::borrow::Cow;

pub const MAX_PASTE_VALUE_SIZE: u32 = 16 * 1024;
pub const DELETE_TEPMLATE: &str = "DELETE";
pub const DELETE_TEMPLATE: &str = "DELETE";
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😉

Comment on lines +55 to +93
impl PasteData {
pub fn create(id: u64, user_id: Option<Principal>, info: PasteDataCreator) -> Self {
PasteData {
id: id.to_string(),
name: info.name,
creator: user_id,
description: info.description,
expire_date: info.expire_date,
content: info.content,
tags: _create_tags(info.tags),
version: 1,
}
}

pub fn update(&mut self, info: PasteDataUpdater) {
if let Some(name) = info.name {
self.name = name;
}
if let Some(desc) = info.description {
self.description = desc;
}
if let Some(content) = info.content {
self.content = content;
}
if let Some(tags) = info.tags {
self.tags = _create_tags(tags);
}

// Increase the number of changes
self.version += 1;
}

// Clear the content of the paste
pub fn clear(&mut self) {
self.name = DELETE_TEMPLATE.to_string();
self.content = DELETE_TEMPLATE.to_string();
self.tags = Vec::new();
}
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i don't understand what is your changes. is it git diff problem?

Comment on lines +108 to +111
.split_whitespace()
.filter(|v| !v.is_empty())
.map(String::from)
.collect()
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is much nice and cleaner. thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants