From b3fce752d240dcb525191fce2f089d9061e846a7 Mon Sep 17 00:00:00 2001 From: Julien Voisin Date: Wed, 6 Aug 2025 04:47:26 +0200 Subject: [PATCH] refactor: replace `Sprintf` with string concatenation There is no need to have go parse the whole format string then introspect the arguments when we an simply use string concatenation. --- internal/http/response/builder.go | 3 +-- internal/storage/entry_query_builder.go | 24 ++++++------------------ 2 files changed, 7 insertions(+), 20 deletions(-) diff --git a/internal/http/response/builder.go b/internal/http/response/builder.go index e2001a82..d9de2131 100644 --- a/internal/http/response/builder.go +++ b/internal/http/response/builder.go @@ -6,7 +6,6 @@ package response // import "miniflux.app/v2/internal/http/response" import ( "compress/flate" "compress/gzip" - "fmt" "io" "log/slog" "net/http" @@ -48,7 +47,7 @@ func (b *Builder) WithBody(body any) *Builder { // WithAttachment forces the document to be downloaded by the web browser. func (b *Builder) WithAttachment(filename string) *Builder { - b.headers["Content-Disposition"] = fmt.Sprintf("attachment; filename=%s", filename) + b.headers["Content-Disposition"] = "attachment; filename=" + filename return b } diff --git a/internal/storage/entry_query_builder.go b/internal/storage/entry_query_builder.go index cc3a03df..3403c388 100644 --- a/internal/storage/entry_query_builder.go +++ b/internal/storage/entry_query_builder.go @@ -191,7 +191,7 @@ func (e *EntryQueryBuilder) WithShareCodeNotEmpty() *EntryQueryBuilder { // WithSorting add a sort expression. func (e *EntryQueryBuilder) WithSorting(column, direction string) *EntryQueryBuilder { - e.sortExpressions = append(e.sortExpressions, fmt.Sprintf("%s %s", column, direction)) + e.sortExpressions = append(e.sortExpressions, column+" "+direction) return e } @@ -224,11 +224,9 @@ func (e *EntryQueryBuilder) CountEntries() (count int, err error) { FROM entries e JOIN feeds f ON f.id = e.feed_id JOIN categories c ON c.id = f.category_id - WHERE %s - ` - condition := e.buildCondition() + WHERE ` + e.buildCondition() - err = e.store.db.QueryRow(fmt.Sprintf(query, condition), e.args...).Scan(&count) + err = e.store.db.QueryRow(query, e.args...).Scan(&count) if err != nil { return 0, fmt.Errorf("store: unable to count entries: %v", err) } @@ -308,12 +306,7 @@ func (e *EntryQueryBuilder) GetEntries() (model.Entries, error) { icons i ON i.id=fi.icon_id LEFT JOIN users u ON u.id=e.user_id - WHERE %s %s - ` - - condition := e.buildCondition() - sorting := e.buildSorting() - query = fmt.Sprintf(query, condition, sorting) + WHERE ` + e.buildCondition() + " " + e.buildSorting() rows, err := e.store.db.Query(query, e.args...) if err != nil { @@ -426,12 +419,7 @@ func (e *EntryQueryBuilder) GetEntryIDs() ([]int64, error) { feeds f ON f.id=e.feed_id - WHERE - %s %s - ` - - condition := e.buildCondition() - query = fmt.Sprintf(query, condition, e.buildSorting()) + WHERE ` + e.buildCondition() + " " + e.buildSorting() rows, err := e.store.db.Query(query, e.args...) if err != nil { @@ -462,7 +450,7 @@ func (e *EntryQueryBuilder) buildSorting() string { var parts string if len(e.sortExpressions) > 0 { - parts += fmt.Sprintf(" ORDER BY %s", strings.Join(e.sortExpressions, ", ")) + parts += " ORDER BY " + strings.Join(e.sortExpressions, ", ") } if e.limit > 0 {