Refactor fetch functions to use new FullData.Insert{Feed,Page} funcs
This commit is contained in:
@@ -9,7 +9,6 @@ package fetch
|
||||
import (
|
||||
"fmt"
|
||||
"net/url"
|
||||
"reflect"
|
||||
|
||||
"golang.nytpu.com/comitium/core"
|
||||
)
|
||||
@@ -43,29 +42,3 @@ func Page(data *core.FullData, remote *url.URL, title string) error {
|
||||
return fmt.Errorf("Unsupported protocol '%s'", remote.Scheme)
|
||||
}
|
||||
}
|
||||
|
||||
// InsertFeed will insert or update a core.Feed in a core.FullData
|
||||
func InsertFeed(data *core.FullData, new *core.Feed, remote *url.URL) {
|
||||
data.FeedsMu.Lock()
|
||||
oldFeed, ok := data.Feeds[*remote]
|
||||
if !ok || !reflect.DeepEqual(new, oldFeed) {
|
||||
// Feeds are different, or there was never an old one
|
||||
data.Feeds[*remote] = new
|
||||
data.FeedsMu.Unlock()
|
||||
} else {
|
||||
data.FeedsMu.Unlock()
|
||||
}
|
||||
}
|
||||
|
||||
// InsertFeed will insert or update a core.Page in a core.FullData
|
||||
func InsertPage(data *core.FullData, new *core.Page, remote *url.URL) {
|
||||
data.PagesMu.Lock()
|
||||
_, ok := data.Pages[*remote]
|
||||
if !ok || data.Pages[*remote].Hash != new.Hash {
|
||||
// pages are different, or there was never an old one
|
||||
data.Pages[*remote] = new
|
||||
data.PagesMu.Unlock()
|
||||
} else {
|
||||
data.PagesMu.Unlock()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user