use "published" instead of "updated" (#1486)

This commit is contained in:
Athou
2024-07-14 19:39:37 +02:00
parent f0e3ac8fcb
commit 1ce39a419e
5 changed files with 19 additions and 11 deletions

View File

@@ -59,7 +59,7 @@ public class FeedRefreshWorker {
Integer maxEntriesAgeDays = config.getApplicationSettings().getMaxEntriesAgeDays(); Integer maxEntriesAgeDays = config.getApplicationSettings().getMaxEntriesAgeDays();
if (maxEntriesAgeDays > 0) { if (maxEntriesAgeDays > 0) {
Instant threshold = Instant.now().minus(Duration.ofDays(maxEntriesAgeDays)); Instant threshold = Instant.now().minus(Duration.ofDays(maxEntriesAgeDays));
entries = entries.stream().filter(entry -> entry.updated().isAfter(threshold)).toList(); entries = entries.stream().filter(entry -> entry.published().isAfter(threshold)).toList();
} }
String urlAfterRedirect = result.urlAfterRedirect(); String urlAfterRedirect = result.urlAfterRedirect();

View File

@@ -73,7 +73,7 @@ public class FeedParser {
String title = feed.getTitle(); String title = feed.getTitle();
String link = feed.getLink(); String link = feed.getLink();
List<Entry> entries = buildEntries(feed, feedUrl); List<Entry> entries = buildEntries(feed, feedUrl);
Instant lastEntryDate = entries.stream().findFirst().map(Entry::updated).orElse(null); Instant lastEntryDate = entries.stream().findFirst().map(Entry::published).orElse(null);
Instant lastPublishedDate = toValidInstant(feed.getPublishedDate(), false); Instant lastPublishedDate = toValidInstant(feed.getPublishedDate(), false);
if (lastPublishedDate == null || lastEntryDate != null && lastPublishedDate.isBefore(lastEntryDate)) { if (lastPublishedDate == null || lastEntryDate != null && lastPublishedDate.isBefore(lastEntryDate)) {
lastPublishedDate = lastEntryDate; lastPublishedDate = lastEntryDate;
@@ -123,13 +123,13 @@ public class FeedParser {
url = guid; url = guid;
} }
Instant updated = buildEntryUpdateDate(item); Instant publishedDate = buildEntryPublishedDate(item);
Content content = buildContent(item); Content content = buildContent(item);
entries.add(new Entry(guid, url, updated, content)); entries.add(new Entry(guid, url, publishedDate, content));
} }
entries.sort(Comparator.comparing(Entry::updated).reversed()); entries.sort(Comparator.comparing(Entry::published).reversed());
return entries; return entries;
} }
@@ -154,10 +154,10 @@ public class FeedParser {
return new Enclosure(enclosure.getUrl(), enclosure.getType()); return new Enclosure(enclosure.getUrl(), enclosure.getType());
} }
private Instant buildEntryUpdateDate(SyndEntry item) { private Instant buildEntryPublishedDate(SyndEntry item) {
Date date = item.getUpdatedDate(); Date date = item.getPublishedDate();
if (date == null) { if (date == null) {
date = item.getPublishedDate(); date = item.getUpdatedDate();
} }
return toValidInstant(date, true); return toValidInstant(date, true);
} }
@@ -262,7 +262,7 @@ public class FeedParser {
SummaryStatistics stats = new SummaryStatistics(); SummaryStatistics stats = new SummaryStatistics();
for (int i = 0; i < entries.size() - 1; i++) { for (int i = 0; i < entries.size() - 1; i++) {
long diff = Math.abs(entries.get(i).updated().toEpochMilli() - entries.get(i + 1).updated().toEpochMilli()); long diff = Math.abs(entries.get(i).published().toEpochMilli() - entries.get(i + 1).published().toEpochMilli());
stats.addValue(diff); stats.addValue(diff);
} }
return (long) stats.getMean(); return (long) stats.getMean();

View File

@@ -5,7 +5,7 @@ import java.util.List;
public record FeedParserResult(String title, String link, Instant lastPublishedDate, Long averageEntryInterval, Instant lastEntryDate, public record FeedParserResult(String title, String link, Instant lastPublishedDate, Long averageEntryInterval, Instant lastEntryDate,
List<Entry> entries) { List<Entry> entries) {
public record Entry(String guid, String url, Instant updated, Content content) { public record Entry(String guid, String url, Instant published, Content content) {
} }
public record Content(String title, String content, String author, String categories, Enclosure enclosure, Media media) { public record Content(String title, String content, String author, String categories, Enclosure enclosure, Media media) {

View File

@@ -37,9 +37,17 @@ public class FeedEntry extends AbstractModel {
@Column(length = 2048) @Column(length = 2048)
private String url; private String url;
/**
* the moment the entry was inserted in the database
*/
@Column @Column
private Instant inserted; private Instant inserted;
/**
* the moment the entry was published in the feed
*
* TODO rename the field to published
*/
@Column @Column
private Instant updated; private Instant updated;

View File

@@ -45,7 +45,7 @@ public class FeedEntryService {
feedEntry.setGuid(FeedUtils.truncate(entry.guid(), 2048)); feedEntry.setGuid(FeedUtils.truncate(entry.guid(), 2048));
feedEntry.setGuidHash(Digests.sha1Hex(entry.guid())); feedEntry.setGuidHash(Digests.sha1Hex(entry.guid()));
feedEntry.setUrl(FeedUtils.truncate(entry.url(), 2048)); feedEntry.setUrl(FeedUtils.truncate(entry.url(), 2048));
feedEntry.setUpdated(entry.updated()); feedEntry.setUpdated(entry.published());
feedEntry.setInserted(Instant.now()); feedEntry.setInserted(Instant.now());
feedEntry.setFeed(feed); feedEntry.setFeed(feed);
feedEntry.setContent(feedEntryContentService.findOrCreate(entry.content(), feed.getLink())); feedEntry.setContent(feedEntryContentService.findOrCreate(entry.content(), feed.getLink()));