Minor concatenation-related simplifications in internal/storage/
Use plain strings concatenation instead of building an array and then joining it.
This commit is contained in:
parent
863a5b3648
commit
e2ee74428a
3 changed files with 14 additions and 16 deletions
|
@ -60,18 +60,16 @@ func (b *BatchBuilder) WithoutDisabledFeeds() *BatchBuilder {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *BatchBuilder) FetchJobs() (jobs model.JobList, err error) {
|
func (b *BatchBuilder) FetchJobs() (jobs model.JobList, err error) {
|
||||||
var parts []string
|
query := `SELECT id, user_id FROM feeds`
|
||||||
parts = append(parts, `SELECT id, user_id FROM feeds`)
|
|
||||||
|
|
||||||
if len(b.conditions) > 0 {
|
if len(b.conditions) > 0 {
|
||||||
parts = append(parts, fmt.Sprintf("WHERE %s", strings.Join(b.conditions, " AND ")))
|
query += fmt.Sprintf(" WHERE %s", strings.Join(b.conditions, " AND "))
|
||||||
}
|
}
|
||||||
|
|
||||||
if b.limit > 0 {
|
if b.limit > 0 {
|
||||||
parts = append(parts, fmt.Sprintf("ORDER BY next_check_at ASC LIMIT %d", b.limit))
|
query += fmt.Sprintf(" ORDER BY next_check_at ASC LIMIT %d", b.limit)
|
||||||
}
|
}
|
||||||
|
|
||||||
query := strings.Join(parts, " ")
|
|
||||||
rows, err := b.db.Query(query, b.args...)
|
rows, err := b.db.Query(query, b.args...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf(`store: unable to fetch batch of jobs: %v`, err)
|
return nil, fmt.Errorf(`store: unable to fetch batch of jobs: %v`, err)
|
||||||
|
|
|
@ -439,21 +439,21 @@ func (e *EntryQueryBuilder) buildCondition() string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *EntryQueryBuilder) buildSorting() string {
|
func (e *EntryQueryBuilder) buildSorting() string {
|
||||||
var parts []string
|
var parts string
|
||||||
|
|
||||||
if len(e.sortExpressions) > 0 {
|
if len(e.sortExpressions) > 0 {
|
||||||
parts = append(parts, fmt.Sprintf(`ORDER BY %s`, strings.Join(e.sortExpressions, ", ")))
|
parts += fmt.Sprintf(" ORDER BY %s", strings.Join(e.sortExpressions, ", "))
|
||||||
}
|
}
|
||||||
|
|
||||||
if e.limit > 0 {
|
if e.limit > 0 {
|
||||||
parts = append(parts, fmt.Sprintf(`LIMIT %d`, e.limit))
|
parts += fmt.Sprintf(" LIMIT %d", e.limit)
|
||||||
}
|
}
|
||||||
|
|
||||||
if e.offset > 0 {
|
if e.offset > 0 {
|
||||||
parts = append(parts, fmt.Sprintf(`OFFSET %d`, e.offset))
|
parts += fmt.Sprintf(" OFFSET %d", e.offset)
|
||||||
}
|
}
|
||||||
|
|
||||||
return strings.Join(parts, " ")
|
return parts
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewEntryQueryBuilder returns a new EntryQueryBuilder.
|
// NewEntryQueryBuilder returns a new EntryQueryBuilder.
|
||||||
|
|
|
@ -91,25 +91,25 @@ func (f *FeedQueryBuilder) buildCounterCondition() string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *FeedQueryBuilder) buildSorting() string {
|
func (f *FeedQueryBuilder) buildSorting() string {
|
||||||
var parts []string
|
var parts string
|
||||||
|
|
||||||
if len(f.sortExpressions) > 0 {
|
if len(f.sortExpressions) > 0 {
|
||||||
parts = append(parts, fmt.Sprintf(`ORDER BY %s`, strings.Join(f.sortExpressions, ", ")))
|
parts += fmt.Sprintf(" ORDER BY %s", strings.Join(f.sortExpressions, ", "))
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(parts) > 0 {
|
if len(parts) > 0 {
|
||||||
parts = append(parts, ", lower(f.title) ASC")
|
parts += ", lower(f.title) ASC"
|
||||||
}
|
}
|
||||||
|
|
||||||
if f.limit > 0 {
|
if f.limit > 0 {
|
||||||
parts = append(parts, fmt.Sprintf(`LIMIT %d`, f.limit))
|
parts += fmt.Sprintf(" LIMIT %d", f.limit)
|
||||||
}
|
}
|
||||||
|
|
||||||
if f.offset > 0 {
|
if f.offset > 0 {
|
||||||
parts = append(parts, fmt.Sprintf(`OFFSET %d`, f.offset))
|
parts += fmt.Sprintf(" OFFSET %d", f.offset)
|
||||||
}
|
}
|
||||||
|
|
||||||
return strings.Join(parts, " ")
|
return parts
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetFeed returns a single feed that match the condition.
|
// GetFeed returns a single feed that match the condition.
|
||||||
|
|
Loading…
Reference in a new issue