Skip to content

Commit

Permalink
Fix get articles condition
Browse files Browse the repository at this point in the history
  • Loading branch information
rupinr committed Nov 2, 2024
1 parent 22dd2cd commit d7b1227
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
10 changes: 8 additions & 2 deletions repository/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,10 +178,16 @@ func SetLastProcessedAt(subscriptionId uint) {

func GetArticlesAfterLastProcessedTime(fromDate time.Time, sites []entity.Site) []entity.Article {
var articles []entity.Article
twoDaysAgo := time.Now().AddDate(0, 0, -2)
emptyDate := time.Time{}
var actualFromDate time.Time
if fromDate.Equal(emptyDate) {
actualFromDate = time.Now().AddDate(0, 0, -2)
} else {
actualFromDate = fromDate
}
dto.MapToUrls(sites)
db().
Where("created_at > ? AND created_at < ?", fromDate, twoDaysAgo).
Where("created_at > ?", actualFromDate).
Where("site IN ?", dto.MapToUrls(sites)).
Find(&articles)
return articles
Expand Down
2 changes: 1 addition & 1 deletion tasks/tasks.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func SendNewsletter() {
articles := repository.GetArticlesAfterLastProcessedTime(subscription.LastProcessedAt, subscription.Sites)

if len(articles) == 0 {
logger.Log.Debug("No articles found for the subscription, not sending email")
logger.Log.Debug("No articles found for the subscription, not sending email for", "sub_id", subscription.ID)
continue
}

Expand Down

0 comments on commit d7b1227

Please sign in to comment.