Explorar el Código

Minor concatenation-related simplifications in internal/storage/

Use plain strings concatenation instead of
building an array and then joining it.
jvoisin hace 2 años
padre
commit
e2ee74428a

+ 3 - 5
internal/storage/batch.go

@@ -60,18 +60,16 @@ func (b *BatchBuilder) WithoutDisabledFeeds() *BatchBuilder {
 }
 
 func (b *BatchBuilder) FetchJobs() (jobs model.JobList, err error) {
-	var parts []string
-	parts = append(parts, `SELECT id, user_id FROM feeds`)
+	query := `SELECT id, user_id FROM feeds`
 
 	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 {
-		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...)
 	if err != nil {
 		return nil, fmt.Errorf(`store: unable to fetch batch of jobs: %v`, err)

+ 5 - 5
internal/storage/entry_query_builder.go

@@ -439,21 +439,21 @@ func (e *EntryQueryBuilder) buildCondition() string {
 }
 
 func (e *EntryQueryBuilder) buildSorting() string {
-	var parts []string
+	var parts string
 
 	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 {
-		parts = append(parts, fmt.Sprintf(`LIMIT %d`, e.limit))
+		parts += fmt.Sprintf(" LIMIT %d", e.limit)
 	}
 
 	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.

+ 6 - 6
internal/storage/feed_query_builder.go

@@ -91,25 +91,25 @@ func (f *FeedQueryBuilder) buildCounterCondition() string {
 }
 
 func (f *FeedQueryBuilder) buildSorting() string {
-	var parts []string
+	var parts string
 
 	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 {
-		parts = append(parts, ", lower(f.title) ASC")
+		parts += ", lower(f.title) ASC"
 	}
 
 	if f.limit > 0 {
-		parts = append(parts, fmt.Sprintf(`LIMIT %d`, f.limit))
+		parts += fmt.Sprintf(" LIMIT %d", f.limit)
 	}
 
 	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.