From 8b78ddeb68daf7cde07d3204414b7bcdc5cdbef5 Mon Sep 17 00:00:00 2001 From: Integral Date: Fri, 20 Dec 2024 04:42:01 +0800 Subject: [PATCH] refactor: avoid using format! when String creation is unnecessary (#5268) --- crates/apub/src/fetcher/markdown_links.rs | 3 ++- crates/routes/src/feeds.rs | 4 ++-- crates/utils/src/utils/markdown/image_links.rs | 3 ++- src/scheduled_tasks.rs | 6 ++---- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/crates/apub/src/fetcher/markdown_links.rs b/crates/apub/src/fetcher/markdown_links.rs index d83aae515..a5e51caa7 100644 --- a/crates/apub/src/fetcher/markdown_links.rs +++ b/crates/apub/src/fetcher/markdown_links.rs @@ -42,7 +42,8 @@ pub async fn markdown_rewrite_remote_links( let mut local_url = local_url.to_string(); // restore title if let Some(extra) = extra { - local_url = format!("{local_url} {extra}"); + local_url.push(' '); + local_url.push_str(extra); } src.replace_range(start..end, local_url.as_str()); } diff --git a/crates/routes/src/feeds.rs b/crates/routes/src/feeds.rs index 55e9cc7f3..cd1ca3e98 100644 --- a/crates/routes/src/feeds.rs +++ b/crates/routes/src/feeds.rs @@ -454,7 +454,6 @@ fn build_item( protocol_and_hostname: &str, ) -> LemmyResult { // TODO add images - let author_url = format!("{protocol_and_hostname}/u/{creator_name}"); let guid = Some(Guid { permalink: true, value: url.to_owned(), @@ -464,7 +463,8 @@ fn build_item( Ok(Item { title: Some(format!("Reply from {creator_name}")), author: Some(format!( - "/u/{creator_name} (link)" + "/u/{creator_name} (link)", + format_args!("{protocol_and_hostname}/u/{creator_name}") )), pub_date: Some(published.to_rfc2822()), comments: Some(url.to_owned()), diff --git a/crates/utils/src/utils/markdown/image_links.rs b/crates/utils/src/utils/markdown/image_links.rs index 0990b1bc7..7914452ff 100644 --- a/crates/utils/src/utils/markdown/image_links.rs +++ b/crates/utils/src/utils/markdown/image_links.rs @@ -24,7 +24,8 @@ pub fn markdown_rewrite_image_links(mut src: String) -> (String, Vec) { ); // restore custom emoji format if let Some(extra) = extra { - proxied = format!("{proxied} {extra}"); + proxied.push(' '); + proxied.push_str(extra); } src.replace_range(start..end, &proxied); } diff --git a/src/scheduled_tasks.rs b/src/scheduled_tasks.rs index 3406bf694..53c0b888b 100644 --- a/src/scheduled_tasks.rs +++ b/src/scheduled_tasks.rs @@ -190,10 +190,8 @@ async fn process_ranks_in_batches( UPDATE {aggregates_table} a {set_clause} FROM batch WHERE a.{id_column} = batch.{id_column} RETURNING a.published; "#, - id_column = format!("{table_name}_id"), - aggregates_table = format!("{table_name}_aggregates"), - set_clause = set_clause, - where_clause = where_clause + id_column = format_args!("{table_name}_id"), + aggregates_table = format_args!("{table_name}_aggregates"), )) .bind::(previous_batch_last_published) .bind::(update_batch_size)