Skip to content

Commit

Permalink
Fix feed entries from midnight on a given day being completely ignored
Browse files Browse the repository at this point in the history
Signed-off-by: AKP <tom@tdpain.net>
  • Loading branch information
codemicro committed May 8, 2022
1 parent 11bdee1 commit 2acd662
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),

## [Unreleased]

## [0.2.2] - 2022-05-08
### Fixed
* Feed entries from midnight on a given day are no longer mistakenly ignored.

## [0.2.1] - 2022-04-29
### Fixed
* Digest emails no longer contain three extra days worth of feed items
Expand Down
24 changes: 22 additions & 2 deletions walrss/internal/rss/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,21 @@ func ProcessUserFeed(st *state.State, user *db.User, progressChannel chan string
pf.Error = err
reportProgress(progressChannel, "Failed to fetch: "+err.Error())
} else {
pf.Items = filterFeedContent(rawFeed, time.Now().UTC().Add(-interval))
// Instead of just using the interval, we want to include everything from the earliest day specified by
// the interval.
//
// Say we were running at 5AM and we had an interval of 24 hours. We'd select all the feed items from up to
// 5AM from the day before. Sometimes, this would end up with feeds published at exactly midnight being
// ignored, for example.
//
// This doesn't explain it well, but I don't quite understand it, so this is what you're getting.

t := time.Now().UTC().Add(-interval)

pf.Items = filterFeedContent(
rawFeed,
time.Date(t.Year(), t.Month(), t.Day(), 0, 0, 0, 0, time.UTC),
)
}
processedFeeds = append(processedFeeds, pf)
}
Expand Down Expand Up @@ -161,7 +175,13 @@ func filterFeedContent(feed *gofeed.Feed, earliestPublishTime time.Time) []*feed
var o []*feedItem

for _, item := range feed.Items {
if item.PublishedParsed != nil && item.PublishedParsed.After(earliestPublishTime) {
if item.PublishedParsed == nil {
continue
}

*item.PublishedParsed = item.PublishedParsed.UTC()

if item.PublishedParsed.After(earliestPublishTime) || item.PublishedParsed.Equal(earliestPublishTime) {
o = append(o, &feedItem{
Title: strings.TrimSpace(item.Title),
URL: item.Link,
Expand Down

0 comments on commit 2acd662

Please sign in to comment.