mirror of
https://github.com/derfenix/webarchive.git
synced 2026-03-11 22:40:58 +03:00
Refactoring
This commit is contained in:
@@ -169,8 +169,8 @@ func (p *Page) ListAll(ctx context.Context) ([]*entity.Page, error) {
|
|||||||
return pages, nil
|
return pages, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Page) ListUnprocessed(ctx context.Context) ([]*entity.Page, error) {
|
func (p *Page) ListUnprocessed(ctx context.Context) ([]entity.Page, error) {
|
||||||
pages := make([]*entity.Page, 0, 100)
|
pages := make([]entity.Page, 0, 100)
|
||||||
|
|
||||||
err := p.db.View(func(txn *badger.Txn) error {
|
err := p.db.View(func(txn *badger.Txn) error {
|
||||||
iterator := txn.NewIterator(badger.DefaultIteratorOptions)
|
iterator := txn.NewIterator(badger.DefaultIteratorOptions)
|
||||||
@@ -200,16 +200,8 @@ func (p *Page) ListUnprocessed(ctx context.Context) ([]*entity.Page, error) {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
pages = append(pages, &entity.Page{
|
//goland:noinspection GoVetCopyLock
|
||||||
ID: page.ID,
|
pages = append(pages, page) //nolint:govet // didn't touch the lock here
|
||||||
URL: page.URL,
|
|
||||||
Description: page.Description,
|
|
||||||
Created: page.Created,
|
|
||||||
Formats: page.Formats,
|
|
||||||
Version: page.Version,
|
|
||||||
Status: page.Status,
|
|
||||||
Meta: page.Meta,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
@@ -41,6 +41,7 @@ const (
|
|||||||
type Meta struct {
|
type Meta struct {
|
||||||
Title string
|
Title string
|
||||||
Description string
|
Description string
|
||||||
|
Encoding string
|
||||||
Error string
|
Error string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import (
|
|||||||
|
|
||||||
type Pages interface {
|
type Pages interface {
|
||||||
Save(ctx context.Context, page *Page) error
|
Save(ctx context.Context, page *Page) error
|
||||||
ListUnprocessed(ctx context.Context) ([]*Page, error)
|
ListUnprocessed(ctx context.Context) ([]Page, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewWorker(ch chan *Page, pages Pages, processor Processor, log *zap.Logger) *Worker {
|
func NewWorker(ch chan *Page, pages Pages, processor Processor, log *zap.Logger) *Worker {
|
||||||
@@ -37,7 +37,7 @@ func (w *Worker) Start(ctx context.Context, wg *sync.WaitGroup) {
|
|||||||
w.log.Error("failed to get unprocessed pages", zap.Error(err))
|
w.log.Error("failed to get unprocessed pages", zap.Error(err))
|
||||||
} else {
|
} else {
|
||||||
for i := range unprocessed {
|
for i := range unprocessed {
|
||||||
w.ch <- unprocessed[i]
|
w.ch <- &unprocessed[i]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|||||||
Reference in New Issue
Block a user