diff --git a/repository/repository.go b/repository/repository.go index ff20209..ceec59b 100644 --- a/repository/repository.go +++ b/repository/repository.go @@ -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 diff --git a/tasks/tasks.go b/tasks/tasks.go index 6e00921..c77d73d 100644 --- a/tasks/tasks.go +++ b/tasks/tasks.go @@ -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 }