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:
parent
e342a4f143
commit
c4a2afb7b7
12 changed files with 58 additions and 11 deletions
|
@ -16,10 +16,8 @@ import (
|
|||
|
||||
var ErrFeedFormatNotDetected = errors.New("parser: unable to detect feed format")
|
||||
|
||||
// ParseFeed analyzes the input data and returns a normalized feed object.
|
||||
func ParseFeed(baseURL string, r io.ReadSeeker) (*model.Feed, error) {
|
||||
r.Seek(0, io.SeekStart)
|
||||
format, version := DetectFeedFormat(r)
|
||||
// ParseFeedWithFormat returns a normalized feed object.
|
||||
func ParseFeedWithFormat(baseURL string, r io.ReadSeeker, format, version string) (*model.Feed, error) {
|
||||
switch format {
|
||||
case FormatAtom:
|
||||
r.Seek(0, io.SeekStart)
|
||||
|
@ -37,3 +35,10 @@ func ParseFeed(baseURL string, r io.ReadSeeker) (*model.Feed, error) {
|
|||
return nil, ErrFeedFormatNotDetected
|
||||
}
|
||||
}
|
||||
|
||||
// ParseFeed analyzes the input data and returns a normalized feed object.
|
||||
func ParseFeed(baseURL string, r io.ReadSeeker) (*model.Feed, error) {
|
||||
r.Seek(0, io.SeekStart)
|
||||
format, version := DetectFeedFormat(r)
|
||||
return ParseFeedWithFormat(baseURL, r, format, version)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue