forked from Archives/Athou_commafeed
use "published" instead of "updated" (#1486)
This commit is contained in:
@@ -59,7 +59,7 @@ public class FeedRefreshWorker {
|
||||
Integer maxEntriesAgeDays = config.getApplicationSettings().getMaxEntriesAgeDays();
|
||||
if (maxEntriesAgeDays > 0) {
|
||||
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();
|
||||
|
||||
@@ -73,7 +73,7 @@ public class FeedParser {
|
||||
String title = feed.getTitle();
|
||||
String link = feed.getLink();
|
||||
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);
|
||||
if (lastPublishedDate == null || lastEntryDate != null && lastPublishedDate.isBefore(lastEntryDate)) {
|
||||
lastPublishedDate = lastEntryDate;
|
||||
@@ -123,13 +123,13 @@ public class FeedParser {
|
||||
url = guid;
|
||||
}
|
||||
|
||||
Instant updated = buildEntryUpdateDate(item);
|
||||
Instant publishedDate = buildEntryPublishedDate(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;
|
||||
}
|
||||
|
||||
@@ -154,10 +154,10 @@ public class FeedParser {
|
||||
return new Enclosure(enclosure.getUrl(), enclosure.getType());
|
||||
}
|
||||
|
||||
private Instant buildEntryUpdateDate(SyndEntry item) {
|
||||
Date date = item.getUpdatedDate();
|
||||
private Instant buildEntryPublishedDate(SyndEntry item) {
|
||||
Date date = item.getPublishedDate();
|
||||
if (date == null) {
|
||||
date = item.getPublishedDate();
|
||||
date = item.getUpdatedDate();
|
||||
}
|
||||
return toValidInstant(date, true);
|
||||
}
|
||||
@@ -262,7 +262,7 @@ public class FeedParser {
|
||||
|
||||
SummaryStatistics stats = new SummaryStatistics();
|
||||
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);
|
||||
}
|
||||
return (long) stats.getMean();
|
||||
|
||||
@@ -5,7 +5,7 @@ import java.util.List;
|
||||
|
||||
public record FeedParserResult(String title, String link, Instant lastPublishedDate, Long averageEntryInterval, Instant lastEntryDate,
|
||||
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) {
|
||||
|
||||
@@ -37,9 +37,17 @@ public class FeedEntry extends AbstractModel {
|
||||
@Column(length = 2048)
|
||||
private String url;
|
||||
|
||||
/**
|
||||
* the moment the entry was inserted in the database
|
||||
*/
|
||||
@Column
|
||||
private Instant inserted;
|
||||
|
||||
/**
|
||||
* the moment the entry was published in the feed
|
||||
*
|
||||
* TODO rename the field to published
|
||||
*/
|
||||
@Column
|
||||
private Instant updated;
|
||||
|
||||
|
||||
@@ -45,7 +45,7 @@ public class FeedEntryService {
|
||||
feedEntry.setGuid(FeedUtils.truncate(entry.guid(), 2048));
|
||||
feedEntry.setGuidHash(Digests.sha1Hex(entry.guid()));
|
||||
feedEntry.setUrl(FeedUtils.truncate(entry.url(), 2048));
|
||||
feedEntry.setUpdated(entry.updated());
|
||||
feedEntry.setUpdated(entry.published());
|
||||
feedEntry.setInserted(Instant.now());
|
||||
feedEntry.setFeed(feed);
|
||||
feedEntry.setContent(feedEntryContentService.findOrCreate(entry.content(), feed.getLink()));
|
||||
|
||||
Reference in New Issue
Block a user