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:
parent
798bc4cd2d
commit
b3fce752d2
2 changed files with 7 additions and 20 deletions
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue