From 5872710d223bb89024ec2b6569779cd736aebb37 Mon Sep 17 00:00:00 2001 From: jvoisin Date: Mon, 9 Jun 2025 13:08:28 +0200 Subject: [PATCH] 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. --- internal/storage/feed_query_builder.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/internal/storage/feed_query_builder.go b/internal/storage/feed_query_builder.go index 82e6594f..765f7224 100644 --- a/internal/storage/feed_query_builder.go +++ b/internal/storage/feed_query_builder.go @@ -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