mirror of
https://github.com/miniflux/v2.git
synced 2025-08-31 18:31:01 +00:00
Improve storage module
This commit is contained in:
parent
e38333e272
commit
d3883126bf
13 changed files with 505 additions and 317 deletions
|
@ -16,12 +16,14 @@ const maxParsingError = 3
|
|||
func (s *Storage) NewBatch(batchSize int) (jobs model.JobList, err error) {
|
||||
query := `
|
||||
SELECT
|
||||
id, user_id
|
||||
FROM feeds
|
||||
WHERE parsing_error_count < $1 AND disabled is false
|
||||
id,
|
||||
user_id
|
||||
FROM
|
||||
feeds
|
||||
WHERE
|
||||
parsing_error_count < $1 AND disabled is false
|
||||
ORDER BY checked_at ASC LIMIT %d
|
||||
`
|
||||
|
||||
return s.fetchBatchRows(fmt.Sprintf(query, batchSize), maxParsingError)
|
||||
}
|
||||
|
||||
|
@ -31,26 +33,28 @@ func (s *Storage) NewUserBatch(userID int64, batchSize int) (jobs model.JobList,
|
|||
// user refresh manually all his feeds to force a refresh.
|
||||
query := `
|
||||
SELECT
|
||||
id, user_id
|
||||
FROM feeds
|
||||
WHERE user_id=$1 AND disabled is false
|
||||
id,
|
||||
user_id
|
||||
FROM
|
||||
feeds
|
||||
WHERE
|
||||
user_id=$1 AND disabled is false
|
||||
ORDER BY checked_at ASC LIMIT %d
|
||||
`
|
||||
|
||||
return s.fetchBatchRows(fmt.Sprintf(query, batchSize), userID)
|
||||
}
|
||||
|
||||
func (s *Storage) fetchBatchRows(query string, args ...interface{}) (jobs model.JobList, err error) {
|
||||
rows, err := s.db.Query(query, args...)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("unable to fetch batch of jobs: %v", err)
|
||||
return nil, fmt.Errorf(`store: 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 {
|
||||
return nil, fmt.Errorf("unable to fetch job: %v", err)
|
||||
return nil, fmt.Errorf(`store: unable to fetch job: %v`, err)
|
||||
}
|
||||
|
||||
jobs = append(jobs, job)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue