-
-
Notifications
You must be signed in to change notification settings - Fork 137
feat: rss添加标签 #105
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
feat: rss添加标签 #105
Conversation
Jinvic
commented
Nov 17, 2025
- 在rss中添加标签
- 使用fmt.Appendf直接操作字节切片,避免创建中间字符串
There was a problem hiding this 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.Appendffor better memory efficiency - Updated
GetAllEchosrepository 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 |
Copilot
AI
Nov 21, 2025
There was a problem hiding this comment.
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.ImageURLThis pattern is consistently used elsewhere in the codebase (see lines 134-135 and 181-182).
| imageURL = image.ImageURL | |
| imageURL = image.ImageURL | |
| case echoModel.ImageSourceURL: | |
| imageURL = image.ImageURL |
| for _, tag := range msg.Tags { | ||
| renderedContent = fmt.Appendf(renderedContent, "<br /><span class=\"tag\">#%s</span>", tag.Name) | ||
| } |
Copilot
AI
Nov 21, 2025
There was a problem hiding this comment.
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...)| 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...) |