1
0
Fork 0
mirror of https://github.com/miniflux/v2.git synced 2025-08-11 17:51:01 +00:00

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.
This commit is contained in:
Julien Voisin 2025-08-06 04:47:26 +02:00 committed by GitHub
parent 798bc4cd2d
commit b3fce752d2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 7 additions and 20 deletions

View file

@ -6,7 +6,6 @@ package response // import "miniflux.app/v2/internal/http/response"
import ( import (
"compress/flate" "compress/flate"
"compress/gzip" "compress/gzip"
"fmt"
"io" "io"
"log/slog" "log/slog"
"net/http" "net/http"
@ -48,7 +47,7 @@ func (b *Builder) WithBody(body any) *Builder {
// WithAttachment forces the document to be downloaded by the web browser. // WithAttachment forces the document to be downloaded by the web browser.
func (b *Builder) WithAttachment(filename string) *Builder { 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 return b
} }

View file

@ -191,7 +191,7 @@ func (e *EntryQueryBuilder) WithShareCodeNotEmpty() *EntryQueryBuilder {
// WithSorting add a sort expression. // WithSorting add a sort expression.
func (e *EntryQueryBuilder) WithSorting(column, direction string) *EntryQueryBuilder { 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 return e
} }
@ -224,11 +224,9 @@ func (e *EntryQueryBuilder) CountEntries() (count int, err error) {
FROM entries e FROM entries e
JOIN feeds f ON f.id = e.feed_id JOIN feeds f ON f.id = e.feed_id
JOIN categories c ON c.id = f.category_id JOIN categories c ON c.id = f.category_id
WHERE %s WHERE ` + e.buildCondition()
`
condition := 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 { if err != nil {
return 0, fmt.Errorf("store: unable to count entries: %v", err) 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 icons i ON i.id=fi.icon_id
LEFT JOIN LEFT JOIN
users u ON u.id=e.user_id users u ON u.id=e.user_id
WHERE %s %s WHERE ` + e.buildCondition() + " " + e.buildSorting()
`
condition := e.buildCondition()
sorting := e.buildSorting()
query = fmt.Sprintf(query, condition, sorting)
rows, err := e.store.db.Query(query, e.args...) rows, err := e.store.db.Query(query, e.args...)
if err != nil { if err != nil {
@ -426,12 +419,7 @@ func (e *EntryQueryBuilder) GetEntryIDs() ([]int64, error) {
feeds f feeds f
ON ON
f.id=e.feed_id f.id=e.feed_id
WHERE WHERE ` + e.buildCondition() + " " + e.buildSorting()
%s %s
`
condition := e.buildCondition()
query = fmt.Sprintf(query, condition, e.buildSorting())
rows, err := e.store.db.Query(query, e.args...) rows, err := e.store.db.Query(query, e.args...)
if err != nil { if err != nil {
@ -462,7 +450,7 @@ func (e *EntryQueryBuilder) buildSorting() string {
var parts string var parts string
if len(e.sortExpressions) > 0 { 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 { if e.limit > 0 {