mirror of
https://github.com/miniflux/v2.git
synced 2025-08-11 17:51:01 +00:00
perf(storage): minor optimization for FetchJobs
- Replace a call to fmt.Sprintf with a concatenation - Explicit declaration of return values in FetchJobs - Initialize the size of FetchJobs return value to b.limit: when b.limit is used, which is most of the time, this avoid resizing the slice, and when it isn't, the size of the map is set to 0, which is equivalent to the previous situation anyway. - Move a call to `request.UserID(r)` to a lower scope.
This commit is contained in:
parent
76ef8f3579
commit
a6ce5c92dc
2 changed files with 6 additions and 4 deletions
|
@ -55,15 +55,15 @@ func (b *BatchBuilder) WithNextCheckExpired() *BatchBuilder {
|
|||
}
|
||||
|
||||
func (b *BatchBuilder) WithoutDisabledFeeds() *BatchBuilder {
|
||||
b.conditions = append(b.conditions, "disabled is false")
|
||||
b.conditions = append(b.conditions, "disabled IS false")
|
||||
return b
|
||||
}
|
||||
|
||||
func (b *BatchBuilder) FetchJobs() (jobs model.JobList, err error) {
|
||||
func (b *BatchBuilder) FetchJobs() (model.JobList, error) {
|
||||
query := `SELECT id, user_id FROM feeds`
|
||||
|
||||
if len(b.conditions) > 0 {
|
||||
query += fmt.Sprintf(" WHERE %s", strings.Join(b.conditions, " AND "))
|
||||
query += " WHERE " + strings.Join(b.conditions, " AND ")
|
||||
}
|
||||
|
||||
if b.limit > 0 {
|
||||
|
@ -76,6 +76,8 @@ func (b *BatchBuilder) FetchJobs() (jobs model.JobList, err error) {
|
|||
}
|
||||
defer rows.Close()
|
||||
|
||||
jobs := make(model.JobList, 0, b.limit)
|
||||
|
||||
for rows.Next() {
|
||||
var job model.Job
|
||||
if err := rows.Scan(&job.FeedID, &job.UserID); err != nil {
|
||||
|
|
|
@ -33,7 +33,6 @@ func (h *handler) refreshFeed(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
|
||||
func (h *handler) refreshAllFeeds(w http.ResponseWriter, r *http.Request) {
|
||||
userID := request.UserID(r)
|
||||
printer := locale.NewPrinter(request.UserLanguage(r))
|
||||
sess := session.New(h.store, request.SessionID(r))
|
||||
|
||||
|
@ -42,6 +41,7 @@ func (h *handler) refreshAllFeeds(w http.ResponseWriter, r *http.Request) {
|
|||
time := config.Opts.ForceRefreshInterval()
|
||||
sess.NewFlashErrorMessage(printer.Plural("alert.too_many_feeds_refresh", time, time))
|
||||
} else {
|
||||
userID := request.UserID(r)
|
||||
// We allow the end-user to force refresh all its feeds
|
||||
// without taking into consideration the number of errors.
|
||||
batchBuilder := h.store.NewBatchBuilder()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue