1
0
Fork 0
mirror of https://github.com/miniflux/v2.git synced 2025-07-02 16:38:37 +00:00

perf: cache the format of feeds

Detecting the format of a feed accounts for up to 30% of the time spent in
`parser.ParseFeed`. Cache the value once detected, as it'll never change.
This commit is contained in:
jvoisin 2025-02-04 16:12:31 +01:00
parent e342a4f143
commit c4a2afb7b7
12 changed files with 58 additions and 11 deletions

View file

@ -275,7 +275,18 @@ func RefreshFeed(store *storage.Storage, userID, feedID int64, forceRefresh bool
return localizedError
}
updatedFeed, parseErr := parser.ParseFeed(responseHandler.EffectiveURL(), bytes.NewReader(responseBody))
var updatedFeed *model.Feed
var parseErr error
if originalFeed.Format != "" {
format, version := originalFeed.Format, originalFeed.FormatVersion
updatedFeed, parseErr = parser.ParseFeedWithFormat(responseHandler.EffectiveURL(), bytes.NewReader(responseBody), format, version)
if parseErr != nil { // Maybe the feed changed its format.
slog.Warn("Unable to parse feed with the given format", slog.String("feed_url", originalFeed.FeedURL), slog.String("format", format), slog.Any("error", parseErr))
updatedFeed, parseErr = parser.ParseFeed(responseHandler.EffectiveURL(), bytes.NewReader(responseBody))
}
} else {
updatedFeed, parseErr = parser.ParseFeed(responseHandler.EffectiveURL(), bytes.NewReader(responseBody))
}
if parseErr != nil {
localizedError := locale.NewLocalizedErrorWrapper(parseErr, "error.unable_to_parse_feed", parseErr)