diff options
author | Frédéric Guillot <fred@miniflux.net> | 2017-11-21 22:36:00 -0800 |
---|---|---|
committer | Frédéric Guillot <fred@miniflux.net> | 2017-11-21 22:36:00 -0800 |
commit | 855fb06bc93a628108990013813725996a090c17 (patch) | |
tree | 9b250ce620818089c4a630787c580da8bc47ebe1 /storage | |
parent | 480b0d94e2f67e96285ff9265f4c1c81d3c0392d (diff) |
Add feature to refresh all feeds from the user interface
Diffstat (limited to 'storage')
-rw-r--r-- | storage/feed.go | 14 | ||||
-rw-r--r-- | storage/job.go | 21 |
2 files changed, 23 insertions, 12 deletions
diff --git a/storage/feed.go b/storage/feed.go index ec08580..0fab481 100644 --- a/storage/feed.go +++ b/storage/feed.go @@ -8,9 +8,10 @@ import ( "database/sql" "errors" "fmt" + "time" + "github.com/miniflux/miniflux2/helper" "github.com/miniflux/miniflux2/model" - "time" ) func (s *Storage) FeedExists(userID, feedID int64) bool { @@ -31,6 +32,17 @@ func (s *Storage) FeedURLExists(userID int64, feedURL string) bool { return result >= 1 } +// CountFeeds returns the number of feeds that belongs to the given user. +func (s *Storage) CountFeeds(userID int64) int { + var result int + err := s.db.QueryRow(`SELECT count(*) FROM feeds WHERE user_id=$1`, userID).Scan(&result) + if err != nil { + return 0 + } + + return result +} + func (s *Storage) GetFeeds(userID int64) (model.Feeds, error) { defer helper.ExecutionTime(time.Now(), fmt.Sprintf("[Storage:GetFeeds] userID=%d", userID)) diff --git a/storage/job.go b/storage/job.go index 5383a5b..c9ab64c 100644 --- a/storage/job.go +++ b/storage/job.go @@ -6,19 +6,19 @@ package storage import ( "fmt" + "time" + "github.com/miniflux/miniflux2/helper" "github.com/miniflux/miniflux2/model" - "log" - "time" ) const maxParsingError = 3 -func (s *Storage) GetJobs(batchSize int) []model.Job { - defer helper.ExecutionTime(time.Now(), fmt.Sprintf("storage.GetJobs[%d]", batchSize)) - - var jobs []model.Job - query := `SELECT +// NewBatch returns a serie of jobs. +func (s *Storage) NewBatch(batchSize int) (jobs model.JobList, err error) { + defer helper.ExecutionTime(time.Now(), fmt.Sprintf("[Storage:GetJobs] batchSize=%d", batchSize)) + query := ` + SELECT id, user_id FROM feeds WHERE parsing_error_count < $1 @@ -26,19 +26,18 @@ func (s *Storage) GetJobs(batchSize int) []model.Job { rows, err := s.db.Query(fmt.Sprintf(query, batchSize), maxParsingError) if err != nil { - log.Println("Unable to fetch feed jobs:", err) + return nil, fmt.Errorf("unable to fetch batch of jobs: %v", err) } defer rows.Close() for rows.Next() { var job model.Job if err := rows.Scan(&job.FeedID, &job.UserID); err != nil { - log.Println("Unable to fetch feed job:", err) - break + return nil, fmt.Errorf("unable to fetch job: %v", err) } jobs = append(jobs, job) } - return jobs + return jobs, nil } |