mirror of
https://github.com/miniflux/v2.git
synced 2025-06-27 16:36:00 +00:00
perf(storage): optimize away two Sprintf calls
The call to fmt.Sprintf in WithFeedID accounts for more than 20% of the time spent in GetFeed. Use strconv.Itoa instead, as it's much much faster. Also change WithCategoryID in the same way, for consistency's sake.
This commit is contained in:
parent
d2212dee12
commit
5872710d22
1 changed files with 4 additions and 3 deletions
|
@ -6,6 +6,7 @@ package storage // import "miniflux.app/v2/internal/storage"
|
|||
import (
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"miniflux.app/v2/internal/model"
|
||||
|
@ -40,9 +41,9 @@ func NewFeedQueryBuilder(store *Storage, userID int64) *FeedQueryBuilder {
|
|||
// WithCategoryID filter by category ID.
|
||||
func (f *FeedQueryBuilder) WithCategoryID(categoryID int64) *FeedQueryBuilder {
|
||||
if categoryID > 0 {
|
||||
f.conditions = append(f.conditions, fmt.Sprintf("f.category_id = $%d", len(f.args)+1))
|
||||
f.conditions = append(f.conditions, "f.category_id = $"+strconv.Itoa(len(f.args)+1))
|
||||
f.args = append(f.args, categoryID)
|
||||
f.counterConditions = append(f.counterConditions, fmt.Sprintf("f.category_id = $%d", len(f.counterArgs)+1))
|
||||
f.counterConditions = append(f.counterConditions, "f.category_id = $"+strconv.Itoa(len(f.counterArgs)+1))
|
||||
f.counterArgs = append(f.counterArgs, categoryID)
|
||||
f.counterJoinFeeds = true
|
||||
}
|
||||
|
@ -52,7 +53,7 @@ func (f *FeedQueryBuilder) WithCategoryID(categoryID int64) *FeedQueryBuilder {
|
|||
// WithFeedID filter by feed ID.
|
||||
func (f *FeedQueryBuilder) WithFeedID(feedID int64) *FeedQueryBuilder {
|
||||
if feedID > 0 {
|
||||
f.conditions = append(f.conditions, fmt.Sprintf("f.id = $%d", len(f.args)+1))
|
||||
f.conditions = append(f.conditions, "f.id = $"+strconv.Itoa(len(f.args)+1))
|
||||
f.args = append(f.args, feedID)
|
||||
}
|
||||
return f
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue