Преглед изворни кода

Clicking on refresh feeds should refresh only user feeds

Frédéric Guillot пре 8 година
родитељ
комит
f546552a1d
2 измењених фајлова са 20 додато и 3 уклоњено
  1. 2 2
      server/ui/controller/feed.go
  2. 18 1
      storage/job.go

+ 2 - 2
server/ui/controller/feed.go

@@ -13,10 +13,10 @@ import (
 	"github.com/miniflux/miniflux/server/ui/form"
 	"github.com/miniflux/miniflux/server/ui/form"
 )
 )
 
 
-// RefreshAllFeeds refresh all feeds in the background.
+// RefreshAllFeeds refresh all feeds in the background for the current user.
 func (c *Controller) RefreshAllFeeds(ctx *core.Context, request *core.Request, response *core.Response) {
 func (c *Controller) RefreshAllFeeds(ctx *core.Context, request *core.Request, response *core.Response) {
 	user := ctx.LoggedUser()
 	user := ctx.LoggedUser()
-	jobs, err := c.store.NewBatch(c.store.CountFeeds(user.ID))
+	jobs, err := c.store.NewUserBatch(user.ID, c.store.CountFeeds(user.ID))
 	if err != nil {
 	if err != nil {
 		response.HTML().ServerError(err)
 		response.HTML().ServerError(err)
 		return
 		return

+ 18 - 1
storage/job.go

@@ -24,7 +24,24 @@ func (s *Storage) NewBatch(batchSize int) (jobs model.JobList, err error) {
 		WHERE parsing_error_count < $1
 		WHERE parsing_error_count < $1
 		ORDER BY checked_at ASC LIMIT %d`
 		ORDER BY checked_at ASC LIMIT %d`
 
 
-	rows, err := s.db.Query(fmt.Sprintf(query, batchSize), maxParsingError)
+	return s.fetchBatchRows(fmt.Sprintf(query, batchSize), maxParsingError)
+}
+
+// NewUserBatch returns a serie of jobs but only for a given user.
+func (s *Storage) NewUserBatch(userID int64, batchSize int) (jobs model.JobList, err error) {
+	defer helper.ExecutionTime(time.Now(), fmt.Sprintf("[Storage:GetUserJobs] batchSize=%d, userID=%d", batchSize, userID))
+	query := `
+		SELECT
+		id, user_id
+		FROM feeds
+		WHERE user_id=$1 AND parsing_error_count < $2
+		ORDER BY checked_at ASC LIMIT %d`
+
+	return s.fetchBatchRows(fmt.Sprintf(query, batchSize), userID, maxParsingError)
+}
+
+func (s *Storage) fetchBatchRows(query string, args ...interface{}) (jobs model.JobList, err error) {
+	rows, err := s.db.Query(query, args...)
 	if err != nil {
 	if err != nil {
 		return nil, fmt.Errorf("unable to fetch batch of jobs: %v", err)
 		return nil, fmt.Errorf("unable to fetch batch of jobs: %v", err)
 	}
 	}