diff options
| author | nytpu <alex@nytpu.com> | 2021-03-18 10:33:26 -0600 |
|---|---|---|
| committer | nytpu <alex@nytpu.com> | 2021-03-18 10:33:26 -0600 |
| commit | 0441fc93496ac64670f3357d8f13b17c6380baae (patch) | |
| tree | db31f4085ced90703433a0c76845cfbbd57b2e12 /core | |
| parent | f3096c41a696d188d002e06f14794a360f3756f8 (diff) | |
Implement Insert{Feed,Page} on FullData for easy insertions
Diffstat (limited to 'core')
| -rw-r--r-- | core/structs.go | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/core/structs.go b/core/structs.go index 3162877..7e4dc09 100644 --- a/core/structs.go +++ b/core/structs.go @@ -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. |
