Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@Jinvic
Copy link
Contributor

@Jinvic Jinvic commented Nov 17, 2025

  1. 在rss中添加标签
  2. 使用fmt.Appendf直接操作字节切片,避免创建中间字符串

@lin-snow lin-snow self-assigned this Nov 17, 2025
@lin-snow lin-snow added enhancement New feature or request feature labels Nov 17, 2025
@lin-snow lin-snow added this to the v3.0.0 milestone Nov 17, 2025
@Jinvic Jinvic changed the base branch from main to dev November 21, 2025 12:10
@Jinvic Jinvic changed the base branch from dev to main November 21, 2025 12:13
@lin-snow lin-snow requested a review from Copilot November 21, 2025 14:39
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds tag support to the RSS feed feature and optimizes string operations by using fmt.Appendf to directly manipulate byte slices instead of creating intermediate strings.

Key changes:

  • Added tag rendering in RSS feed items by appending HTML span elements with tag names after the main content
  • Refactored image URL generation to use fmt.Appendf for better memory efficiency
  • Updated GetAllEchos repository method to preload tags alongside images

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
internal/service/common/common.go Refactored image processing to use fmt.Appendf and added new logic to render tags as HTML in RSS feed items
internal/repository/common/common.go Added Preload("Tags") to both query paths to ensure tags are loaded when fetching echos for RSS generation

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

),
),
renderedContent...)
imageURL = image.ImageURL
Copy link

Copilot AI Nov 21, 2025

Choose a reason for hiding this comment

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

Missing case for echoModel.ImageSourceURL in the switch statement. When an image has ImageSource set to "url", the imageURL variable will remain empty, resulting in broken image tags in the RSS feed.

Add the missing case:

case echoModel.ImageSourceURL:
    imageURL = image.ImageURL

This pattern is consistently used elsewhere in the codebase (see lines 134-135 and 181-182).

Suggested change
imageURL = image.ImageURL
imageURL = image.ImageURL
case echoModel.ImageSourceURL:
imageURL = image.ImageURL

Copilot uses AI. Check for mistakes.
Comment on lines +348 to 350
for _, tag := range msg.Tags {
renderedContent = fmt.Appendf(renderedContent, "<br /><span class=\"tag\">#%s</span>", tag.Name)
}
Copy link

Copilot AI Nov 21, 2025

Choose a reason for hiding this comment

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

Calling fmt.Appendf repeatedly in a loop causes multiple slice reallocations. Consider accumulating all tag HTML into a separate byte slice first, then appending it once to renderedContent, similar to how images are handled (lines 331-343).

Example:

var tagContent []byte
for _, tag := range msg.Tags {
    tagContent = fmt.Appendf(tagContent, "<br /><span class=\"tag\">#%s</span>", tag.Name)
}
renderedContent = append(renderedContent, tagContent...)
Suggested change
for _, tag := range msg.Tags {
renderedContent = fmt.Appendf(renderedContent, "<br /><span class=\"tag\">#%s</span>", tag.Name)
}
var tagContent []byte
for _, tag := range msg.Tags {
tagContent = fmt.Appendf(tagContent, "<br /><span class=\"tag\">#%s</span>", tag.Name)
}
renderedContent = append(renderedContent, tagContent...)

Copilot uses AI. Check for mistakes.
@lin-snow lin-snow merged commit a6cc9f5 into lin-snow:main Nov 21, 2025
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants