Avoid excessive manual polling with default scheduler

This commit is contained in:
Frédéric Guillot 2023-10-16 21:20:58 -07:00
parent 54eb500315
commit cc44d14722
7 changed files with 40 additions and 15 deletions

View File

@ -5,6 +5,7 @@ package api // import "miniflux.app/v2/internal/api"
import (
json_parser "encoding/json"
"log/slog"
"net/http"
"time"
@ -141,9 +142,14 @@ func (h *handler) refreshCategory(w http.ResponseWriter, r *http.Request) {
return
}
go func() {
h.pool.Push(jobs)
}()
slog.Info(
"Triggered a manual refresh of all feeds for a given category from the API",
slog.Int64("user_id", userID),
slog.Int64("category_id", categoryID),
slog.Int("nb_jobs", len(jobs)),
)
go h.pool.Push(jobs)
json.NoContent(w, r)
}

View File

@ -5,6 +5,7 @@ package api // import "miniflux.app/v2/internal/api"
import (
json_parser "encoding/json"
"log/slog"
"net/http"
"time"
@ -74,9 +75,13 @@ func (h *handler) refreshAllFeeds(w http.ResponseWriter, r *http.Request) {
return
}
go func() {
h.pool.Push(jobs)
}()
slog.Info(
"Triggered a manual refresh of all feeds from the API",
slog.Int64("user_id", userID),
slog.Int("nb_jobs", len(jobs)),
)
go h.pool.Push(jobs)
json.NoContent(w, r)
}

View File

@ -122,7 +122,7 @@ func (f *Feed) ScheduleNextCheck(weeklyCount int) {
}
f.NextCheckAt = time.Now().Add(time.Minute * time.Duration(intervalMinutes))
default:
f.NextCheckAt = time.Now()
f.NextCheckAt = time.Now().Add(time.Minute * time.Duration(config.Opts.PollingFrequency()))
}
}

View File

@ -97,6 +97,10 @@ func TestFeedScheduleNextCheckDefault(t *testing.T) {
if feed.NextCheckAt.IsZero() {
t.Error(`The next_check_at must be set`)
}
if feed.NextCheckAt.After(time.Now().Add(time.Minute * time.Duration(config.Opts.PollingFrequency()))) {
t.Error(`The next_check_at should not be after the now + polling frequency`)
}
}
func TestFeedScheduleNextCheckEntryCountBasedMaxInterval(t *testing.T) {

View File

@ -38,7 +38,7 @@ func (s *Storage) NewUserBatch(userID int64, batchSize int) (jobs model.JobList,
FROM
feeds
WHERE
user_id=$1 AND disabled is false
user_id=$1 AND disabled is false AND next_check_at < now()
ORDER BY next_check_at ASC LIMIT %d
`
return s.fetchBatchRows(fmt.Sprintf(query, batchSize), userID)
@ -55,7 +55,7 @@ func (s *Storage) NewCategoryBatch(userID int64, categoryID int64, batchSize int
FROM
feeds
WHERE
user_id=$1 AND category_id=$2 AND disabled is false
user_id=$1 AND category_id=$2 AND disabled is false AND next_check_at < now()
ORDER BY next_check_at ASC LIMIT %d
`
return s.fetchBatchRows(fmt.Sprintf(query, batchSize), userID, categoryID)

View File

@ -4,6 +4,7 @@
package ui // import "miniflux.app/v2/internal/ui"
import (
"log/slog"
"net/http"
"miniflux.app/v2/internal/http/request"
@ -31,9 +32,14 @@ func (h *handler) refreshCategory(w http.ResponseWriter, r *http.Request) int64
return 0
}
go func() {
h.pool.Push(jobs)
}()
slog.Info(
"Triggered a manual refresh of all feeds for a given category from the web ui",
slog.Int64("user_id", userID),
slog.Int64("category_id", categoryID),
slog.Int("nb_jobs", len(jobs)),
)
go h.pool.Push(jobs)
return categoryID
}

View File

@ -36,9 +36,13 @@ func (h *handler) refreshAllFeeds(w http.ResponseWriter, r *http.Request) {
return
}
go func() {
h.pool.Push(jobs)
}()
slog.Info(
"Triggered a manual refresh of all feeds from the web ui",
slog.Int64("user_id", userID),
slog.Int("nb_jobs", len(jobs)),
)
go h.pool.Push(jobs)
html.Redirect(w, r, route.Path(h.router, "feeds"))
}