1
0
Fork 0
mirror of https://github.com/miniflux/v2.git synced 2025-06-27 16:36:00 +00:00

perf(rss): early return when looking for an item's author

The `sanitizer.StripTags` function is calling `html.NewTokenizer`, which is
allocating a 4096 bytes buffer on the heap, as well a running a complex state
machine to tokenize html. There is no need to do all of this for empty strings.

This commit also fixes a TrimSpace/StripTags call inversion.
This commit is contained in:
jvoisin 2025-06-11 14:15:08 +02:00 committed by Frédéric Guillot
parent f40c1e7f63
commit 60ad19c427

View file

@ -169,8 +169,11 @@ func findFeedAuthor(rssChannel *RSSChannel) string {
author = rssChannel.ManagingEditor author = rssChannel.ManagingEditor
case rssChannel.Webmaster != "": case rssChannel.Webmaster != "":
author = rssChannel.Webmaster author = rssChannel.Webmaster
default:
return ""
} }
return sanitizer.StripTags(strings.TrimSpace(author))
return strings.TrimSpace(sanitizer.StripTags(author))
} }
func findEntryTitle(rssItem *RSSItem) string { func findEntryTitle(rssItem *RSSItem) string {
@ -258,8 +261,10 @@ func findEntryAuthor(rssItem *RSSItem) string {
author = rssItem.PersonName() author = rssItem.PersonName()
case strings.Contains(rssItem.Author.Inner, "<![CDATA["): case strings.Contains(rssItem.Author.Inner, "<![CDATA["):
author = rssItem.Author.Data author = rssItem.Author.Data
default: case rssItem.Author.Inner != "":
author = rssItem.Author.Inner author = rssItem.Author.Inner
default:
return ""
} }
return strings.TrimSpace(sanitizer.StripTags(author)) return strings.TrimSpace(sanitizer.StripTags(author))