Implement Insert{Feed,Page} on FullData for easy insertions
This commit is contained in:
@@ -12,6 +12,7 @@ package core
|
||||
|
||||
import (
|
||||
"net/url"
|
||||
"reflect"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
@@ -90,6 +91,32 @@ func GofeedConvert(f *gofeed.Feed, title string) (*Feed, error) {
|
||||
return new, nil
|
||||
}
|
||||
|
||||
// InsertFeed will insert or update a core.Feed in a core.FullData
|
||||
func (d *FullData) InsertFeed(new *Feed, remote *url.URL) {
|
||||
d.FeedsMu.Lock()
|
||||
oldFeed, ok := d.Feeds[*remote]
|
||||
if !ok || !reflect.DeepEqual(new, oldFeed) {
|
||||
// Feeds are different, or there was never an old one
|
||||
d.Feeds[*remote] = new
|
||||
d.FeedsMu.Unlock()
|
||||
} else {
|
||||
d.FeedsMu.Unlock()
|
||||
}
|
||||
}
|
||||
|
||||
// InsertPage will insert or update a core.Page in a core.FullData
|
||||
func (d *FullData) InsertPage(new *Page, remote *url.URL) {
|
||||
d.PagesMu.Lock()
|
||||
_, ok := d.Pages[*remote]
|
||||
if !ok || d.Pages[*remote].Hash != new.Hash {
|
||||
// pages are different, or there was never an old one
|
||||
d.Pages[*remote] = new
|
||||
d.PagesMu.Unlock()
|
||||
} else {
|
||||
d.PagesMu.Unlock()
|
||||
}
|
||||
}
|
||||
|
||||
// Implement sort.Interface for Feed
|
||||
|
||||
// Len returns the length of Items.
|
||||
|
||||
Reference in New Issue
Block a user