migrate from java.util.Date to java.time

This commit is contained in:
Athou
2024-01-08 20:42:45 +01:00
parent b1a4debb95
commit 69c9988404
35 changed files with 203 additions and 206 deletions

View File

@@ -1,6 +1,6 @@
package com.commafeed.backend.dao;
import java.util.Date;
import java.time.Instant;
import java.util.List;
import org.apache.commons.lang3.StringUtils;
@@ -26,8 +26,8 @@ public class FeedDAO extends GenericDAO<Feed> {
super(sessionFactory);
}
public List<Feed> findNextUpdatable(int count, Date lastLoginThreshold) {
JPAQuery<Feed> query = query().selectFrom(feed).where(feed.disabledUntil.isNull().or(feed.disabledUntil.lt(new Date())));
public List<Feed> findNextUpdatable(int count, Instant lastLoginThreshold) {
JPAQuery<Feed> query = query().selectFrom(feed).where(feed.disabledUntil.isNull().or(feed.disabledUntil.lt(Instant.now())));
if (lastLoginThreshold != null) {
query.where(JPAExpressions.selectOne()
.from(subscription)
@@ -39,7 +39,7 @@ public class FeedDAO extends GenericDAO<Feed> {
return query.orderBy(feed.disabledUntil.asc()).limit(count).fetch();
}
public void setDisabledUntil(List<Long> feedIds, Date date) {
public void setDisabledUntil(List<Long> feedIds, Instant date) {
updateQuery(feed).set(feed.disabledUntil, date).where(feed.id.in(feedIds)).execute();
}

View File

@@ -1,6 +1,6 @@
package com.commafeed.backend.dao;
import java.util.Date;
import java.time.Instant;
import java.util.List;
import org.hibernate.SessionFactory;
@@ -49,7 +49,7 @@ public class FeedEntryDAO extends GenericDAO<FeedEntry> {
/**
* Delete entries older than a certain date
*/
public int deleteEntriesOlderThan(Date olderThan, long max) {
public int deleteEntriesOlderThan(Instant olderThan, long max) {
List<FeedEntry> list = query().selectFrom(entry).where(entry.updated.lt(olderThan)).orderBy(entry.updated.asc()).limit(max).fetch();
return delete(list);
}

View File

@@ -1,8 +1,8 @@
package com.commafeed.backend.dao;
import java.time.Instant;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.Date;
import java.util.List;
import org.apache.commons.collections4.CollectionUtils;
@@ -73,8 +73,8 @@ public class FeedEntryStatusDAO extends GenericDAO<FeedEntryStatus> {
private FeedEntryStatus handleStatus(User user, FeedEntryStatus status, FeedSubscription sub, FeedEntry entry) {
if (status == null) {
Date unreadThreshold = config.getApplicationSettings().getUnreadThreshold();
boolean read = unreadThreshold != null && entry.getUpdated().before(unreadThreshold);
Instant unreadThreshold = config.getApplicationSettings().getUnreadThreshold();
boolean read = unreadThreshold != null && entry.getUpdated().isBefore(unreadThreshold);
status = new FeedEntryStatus(user, sub, entry);
status.setRead(read);
status.setMarkable(!read);
@@ -90,7 +90,8 @@ public class FeedEntryStatusDAO extends GenericDAO<FeedEntryStatus> {
return status;
}
public List<FeedEntryStatus> findStarred(User user, Date newerThan, int offset, int limit, ReadingOrder order, boolean includeContent) {
public List<FeedEntryStatus> findStarred(User user, Instant newerThan, int offset, int limit, ReadingOrder order,
boolean includeContent) {
JPAQuery<FeedEntryStatus> query = query().selectFrom(status).where(status.user.eq(user), status.starred.isTrue());
if (newerThan != null) {
query.where(status.entryInserted.gt(newerThan));
@@ -114,7 +115,8 @@ public class FeedEntryStatusDAO extends GenericDAO<FeedEntryStatus> {
}
private JPAQuery<FeedEntry> buildQuery(User user, FeedSubscription sub, boolean unreadOnly, List<FeedEntryKeyword> keywords,
Date newerThan, int offset, int limit, ReadingOrder order, FeedEntryStatus last, String tag, Long minEntryId, Long maxEntryId) {
Instant newerThan, int offset, int limit, ReadingOrder order, FeedEntryStatus last, String tag, Long minEntryId,
Long maxEntryId) {
JPAQuery<FeedEntry> query = query().selectFrom(entry).where(entry.feed.eq(sub.getFeed()));
@@ -139,7 +141,7 @@ public class FeedEntryStatusDAO extends GenericDAO<FeedEntryStatus> {
or.or(status.read.isFalse());
query.where(or);
Date unreadThreshold = config.getApplicationSettings().getUnreadThreshold();
Instant unreadThreshold = config.getApplicationSettings().getUnreadThreshold();
if (unreadThreshold != null) {
query.where(entry.updated.goe(unreadThreshold));
}
@@ -193,7 +195,7 @@ public class FeedEntryStatusDAO extends GenericDAO<FeedEntryStatus> {
}
public List<FeedEntryStatus> findBySubscriptions(User user, List<FeedSubscription> subs, boolean unreadOnly,
List<FeedEntryKeyword> keywords, Date newerThan, int offset, int limit, ReadingOrder order, boolean includeContent,
List<FeedEntryKeyword> keywords, Instant newerThan, int offset, int limit, ReadingOrder order, boolean includeContent,
boolean onlyIds, String tag, Long minEntryId, Long maxEntryId) {
int capacity = offset + limit;
@@ -208,7 +210,7 @@ public class FeedEntryStatusDAO extends GenericDAO<FeedEntryStatus> {
for (Tuple tuple : tuples) {
Long id = tuple.get(entry.id);
Date updated = tuple.get(entry.updated);
Instant updated = tuple.get(entry.updated);
Long statusId = tuple.get(status.id);
FeedEntryContent content = new FeedEntryContent();
@@ -260,7 +262,7 @@ public class FeedEntryStatusDAO extends GenericDAO<FeedEntryStatus> {
List<Tuple> tuples = query.select(entry.count(), entry.updated.max()).fetch();
for (Tuple tuple : tuples) {
Long count = tuple.get(entry.count());
Date updated = tuple.get(entry.updated.max());
Instant updated = tuple.get(entry.updated.max());
uc = new UnreadCount(subscription.getId(), count == null ? 0 : count, updated);
}
return uc;
@@ -276,7 +278,7 @@ public class FeedEntryStatusDAO extends GenericDAO<FeedEntryStatus> {
return results;
}
public long deleteOldStatuses(Date olderThan, int limit) {
public long deleteOldStatuses(Instant olderThan, int limit) {
List<Long> ids = query().select(status.id)
.from(status)
.where(status.entryInserted.lt(olderThan), status.starred.isFalse())

View File

@@ -1,7 +1,7 @@
package com.commafeed.backend.feed;
import java.io.IOException;
import java.util.Date;
import java.time.Instant;
import java.util.Set;
import org.apache.commons.codec.binary.StringUtils;
@@ -32,8 +32,8 @@ public class FeedFetcher {
private final HttpGetter getter;
private final Set<FeedURLProvider> urlProviders;
public FeedFetcherResult fetch(String feedUrl, boolean extractFeedUrlFromHtml, String lastModified, String eTag, Date lastPublishedDate,
String lastContentHash) throws FeedException, IOException, NotModifiedException {
public FeedFetcherResult fetch(String feedUrl, boolean extractFeedUrlFromHtml, String lastModified, String eTag,
Instant lastPublishedDate, String lastContentHash) throws FeedException, IOException, NotModifiedException {
log.debug("Fetching feed {}", feedUrl);
int timeout = 20000;
@@ -76,8 +76,7 @@ public class FeedFetcher {
etagHeaderValueChanged ? result.getETag() : null);
}
if (lastPublishedDate != null && parserResult.lastPublishedDate() != null
&& lastPublishedDate.getTime() == parserResult.lastPublishedDate().getTime()) {
if (lastPublishedDate != null && lastPublishedDate.equals(parserResult.lastPublishedDate())) {
log.debug("publishedDate not modified: {}", feedUrl);
throw new NotModifiedException("publishedDate not modified",
lastModifiedHeaderValueChanged ? result.getLastModifiedSince() : null,

View File

@@ -1,6 +1,7 @@
package com.commafeed.backend.feed;
import java.util.Date;
import java.time.Duration;
import java.time.Instant;
import java.util.List;
import java.util.concurrent.BlockingDeque;
import java.util.concurrent.CompletableFuture;
@@ -11,8 +12,6 @@ import java.util.concurrent.SynchronousQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import org.apache.commons.lang3.time.DateUtils;
import com.codahale.metrics.Gauge;
import com.codahale.metrics.Meter;
import com.codahale.metrics.MetricRegistry;
@@ -166,12 +165,12 @@ public class FeedRefreshEngine implements Managed {
private List<Feed> getNextUpdatableFeeds(int max) {
return unitOfWork.call(() -> {
Date lastLoginThreshold = Boolean.TRUE.equals(config.getApplicationSettings().getHeavyLoad())
? DateUtils.addDays(new Date(), -30)
Instant lastLoginThreshold = Boolean.TRUE.equals(config.getApplicationSettings().getHeavyLoad())
? Instant.now().minus(Duration.ofDays(30))
: null;
List<Feed> feeds = feedDAO.findNextUpdatable(max, lastLoginThreshold);
// update disabledUntil to prevent feeds from being returned again by feedDAO.findNextUpdatable()
Date nextUpdateDate = DateUtils.addMinutes(new Date(), config.getApplicationSettings().getRefreshIntervalMinutes());
Instant nextUpdateDate = Instant.now().plus(Duration.ofMinutes(config.getApplicationSettings().getRefreshIntervalMinutes()));
feedDAO.setDisabledUntil(feeds.stream().map(AbstractModel::getId).toList(), nextUpdateDate);
return feeds;
});

View File

@@ -1,8 +1,8 @@
package com.commafeed.backend.feed;
import java.util.Date;
import org.apache.commons.lang3.time.DateUtils;
import java.time.Duration;
import java.time.Instant;
import java.time.temporal.ChronoUnit;
import com.commafeed.CommaFeedConfiguration;
@@ -21,61 +21,59 @@ public class FeedRefreshIntervalCalculator {
this.refreshIntervalMinutes = config.getApplicationSettings().getRefreshIntervalMinutes();
}
public Date onFetchSuccess(Date publishedDate, Long averageEntryInterval) {
Date defaultRefreshInterval = getDefaultRefreshInterval();
public Instant onFetchSuccess(Instant publishedDate, Long averageEntryInterval) {
Instant defaultRefreshInterval = getDefaultRefreshInterval();
return heavyLoad ? computeRefreshIntervalForHeavyLoad(publishedDate, averageEntryInterval, defaultRefreshInterval)
: defaultRefreshInterval;
}
public Date onFeedNotModified(Date publishedDate, Long averageEntryInterval) {
Date defaultRefreshInterval = getDefaultRefreshInterval();
return heavyLoad ? computeRefreshIntervalForHeavyLoad(publishedDate, averageEntryInterval, defaultRefreshInterval)
: defaultRefreshInterval;
public Instant onFeedNotModified(Instant publishedDate, Long averageEntryInterval) {
return onFetchSuccess(publishedDate, averageEntryInterval);
}
public Date onFetchError(int errorCount) {
public Instant onFetchError(int errorCount) {
int retriesBeforeDisable = 3;
if (errorCount < retriesBeforeDisable || !heavyLoad) {
return getDefaultRefreshInterval();
}
int disabledHours = Math.min(24 * 7, errorCount - retriesBeforeDisable + 1);
return DateUtils.addHours(new Date(), disabledHours);
return Instant.now().plus(Duration.ofHours(disabledHours));
}
private Date getDefaultRefreshInterval() {
return DateUtils.addMinutes(new Date(), refreshIntervalMinutes);
private Instant getDefaultRefreshInterval() {
return Instant.now().plus(Duration.ofMinutes(refreshIntervalMinutes));
}
private Date computeRefreshIntervalForHeavyLoad(Date publishedDate, Long averageEntryInterval, Date defaultRefreshInterval) {
Date now = new Date();
private Instant computeRefreshIntervalForHeavyLoad(Instant publishedDate, Long averageEntryInterval, Instant defaultRefreshInterval) {
Instant now = Instant.now();
if (publishedDate == null) {
// feed with no entries, recheck in 24 hours
return DateUtils.addHours(now, 24);
} else if (publishedDate.before(DateUtils.addMonths(now, -1))) {
return now.plus(Duration.ofHours(24));
} else if (ChronoUnit.DAYS.between(publishedDate, now) >= 30) {
// older than a month, recheck in 24 hours
return DateUtils.addHours(now, 24);
} else if (publishedDate.before(DateUtils.addDays(now, -14))) {
return now.plus(Duration.ofHours(24));
} else if (ChronoUnit.DAYS.between(publishedDate, now) >= 14) {
// older than two weeks, recheck in 12 hours
return DateUtils.addHours(now, 12);
} else if (publishedDate.before(DateUtils.addDays(now, -7))) {
return now.plus(Duration.ofHours(12));
} else if (ChronoUnit.DAYS.between(publishedDate, now) >= 7) {
// older than a week, recheck in 6 hours
return DateUtils.addHours(now, 6);
return now.plus(Duration.ofHours(6));
} else if (averageEntryInterval != null) {
// use average time between entries to decide when to refresh next, divided by factor
int factor = 2;
// not more than 6 hours
long date = Math.min(DateUtils.addHours(now, 6).getTime(), now.getTime() + averageEntryInterval / factor);
long date = Math.min(now.plus(Duration.ofHours(6)).toEpochMilli(), now.toEpochMilli() + averageEntryInterval / factor);
// not less than default refresh interval
date = Math.max(defaultRefreshInterval.getTime(), date);
date = Math.max(defaultRefreshInterval.toEpochMilli(), date);
return new Date(date);
return Instant.ofEpochMilli(date);
} else {
// unknown case, recheck in 24 hours
return DateUtils.addHours(now, 24);
return now.plus(Duration.ofHours(24));
}
}

View File

@@ -1,8 +1,8 @@
package com.commafeed.backend.feed;
import java.time.Instant;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
@@ -161,7 +161,7 @@ public class FeedRefreshUpdater implements Managed {
if (!processed) {
// requeue asap
feed.setDisabledUntil(new Date(0));
feed.setDisabledUntil(Instant.EPOCH);
}
if (insertedAtLeastOneEntry) {

View File

@@ -1,12 +1,12 @@
package com.commafeed.backend.feed;
import java.time.Duration;
import java.time.Instant;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.Optional;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.time.DateUtils;
import com.codahale.metrics.Meter;
import com.codahale.metrics.MetricRegistry;
@@ -58,8 +58,8 @@ public class FeedRefreshWorker {
Integer maxEntriesAgeDays = config.getApplicationSettings().getMaxEntriesAgeDays();
if (maxEntriesAgeDays > 0) {
Date threshold = DateUtils.addDays(new Date(), -1 * maxEntriesAgeDays);
entries = entries.stream().filter(entry -> entry.updated().after(threshold)).toList();
Instant threshold = Instant.now().minus(Duration.ofDays(maxEntriesAgeDays));
entries = entries.stream().filter(entry -> entry.updated().isAfter(threshold)).toList();
}
String urlAfterRedirect = result.urlAfterRedirect();

View File

@@ -3,6 +3,7 @@ package com.commafeed.backend.feed.parser;
import java.io.StringReader;
import java.nio.charset.Charset;
import java.text.DateFormat;
import java.time.Instant;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.Date;
@@ -50,8 +51,8 @@ public class FeedParser {
private static final Namespace ATOM_10_NS = Namespace.getNamespace("http://www.w3.org/2005/Atom");
private static final Date START = new Date(86400000);
private static final Date END = new Date(1000L * Integer.MAX_VALUE - 86400000);
private static final Instant START = Instant.ofEpochMilli(86400000);
private static final Instant END = Instant.ofEpochMilli(1000L * Integer.MAX_VALUE - 86400000);
private final EncodingDetector encodingDetector;
private final FeedCleaner feedCleaner;
@@ -72,9 +73,9 @@ public class FeedParser {
String title = feed.getTitle();
String link = feed.getLink();
List<Entry> entries = buildEntries(feed, feedUrl);
Date lastEntryDate = entries.stream().findFirst().map(Entry::updated).orElse(null);
Date lastPublishedDate = validateDate(feed.getPublishedDate(), false);
if (lastPublishedDate == null || lastEntryDate != null && lastPublishedDate.before(lastEntryDate)) {
Instant lastEntryDate = entries.stream().findFirst().map(Entry::updated).orElse(null);
Instant lastPublishedDate = toValidInstant(feed.getPublishedDate(), false);
if (lastPublishedDate == null || lastEntryDate != null && lastPublishedDate.isBefore(lastEntryDate)) {
lastPublishedDate = lastEntryDate;
}
Long averageEntryInterval = averageTimeBetweenEntries(entries);
@@ -122,7 +123,7 @@ public class FeedParser {
url = guid;
}
Date updated = buildEntryUpdateDate(item);
Instant updated = buildEntryUpdateDate(item);
Content content = buildContent(item);
entries.add(new Entry(guid, url, updated, content));
@@ -153,15 +154,12 @@ public class FeedParser {
return new Enclosure(enclosure.getUrl(), enclosure.getType());
}
private Date buildEntryUpdateDate(SyndEntry item) {
private Instant buildEntryUpdateDate(SyndEntry item) {
Date date = item.getUpdatedDate();
if (date == null) {
date = item.getPublishedDate();
}
if (date == null) {
date = new Date();
}
return validateDate(date, true);
return toValidInstant(date, true);
}
private String buildEntryUrl(SyndFeed feed, String feedUrl, SyndEntry item) {
@@ -176,19 +174,21 @@ public class FeedParser {
return FeedUtils.toAbsoluteUrl(url, feedLink, feedUrl);
}
private Date validateDate(Date date, boolean nullToNow) {
Date now = new Date();
private Instant toValidInstant(Date date, boolean nullToNow) {
Instant now = Instant.now();
if (date == null) {
return nullToNow ? now : null;
}
if (date.before(START) || date.after(END)) {
Instant instant = date.toInstant();
if (instant.isBefore(START) || instant.isAfter(END)) {
return now;
}
if (date.after(now)) {
if (instant.isAfter(now)) {
return now;
}
return date;
return instant;
}
private String getContent(SyndEntry item) {
@@ -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().getTime() - entries.get(i + 1).updated().getTime());
long diff = Math.abs(entries.get(i).updated().toEpochMilli() - entries.get(i + 1).updated().toEpochMilli());
stats.addValue(diff);
}
return (long) stats.getMean();

View File

@@ -1,11 +1,11 @@
package com.commafeed.backend.feed.parser;
import java.util.Date;
import java.time.Instant;
import java.util.List;
public record FeedParserResult(String title, String link, Date lastPublishedDate, Long averageEntryInterval, Date lastEntryDate,
public record FeedParserResult(String title, String link, Instant lastPublishedDate, Long averageEntryInterval, Instant lastEntryDate,
List<Entry> entries) {
public record Entry(String guid, String url, Date updated, Content content) {
public record Entry(String guid, String url, Instant updated, Content content) {
}
public record Content(String title, String content, String author, String categories, Enclosure enclosure, Media media) {

View File

@@ -1,12 +1,10 @@
package com.commafeed.backend.model;
import java.util.Date;
import java.time.Instant;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.Table;
import jakarta.persistence.Temporal;
import jakarta.persistence.TemporalType;
import lombok.Getter;
import lombok.Setter;
@@ -44,20 +42,20 @@ public class Feed extends AbstractModel {
/**
* Last time we tried to fetch the feed
*/
@Temporal(TemporalType.TIMESTAMP)
private Date lastUpdated;
@Column
private Instant lastUpdated;
/**
* Last publishedDate value in the feed
*/
@Temporal(TemporalType.TIMESTAMP)
private Date lastPublishedDate;
@Column
private Instant lastPublishedDate;
/**
* date of the last entry of the feed
*/
@Temporal(TemporalType.TIMESTAMP)
private Date lastEntryDate;
@Column
private Instant lastEntryDate;
/**
* error message while retrieving the feed
@@ -73,8 +71,8 @@ public class Feed extends AbstractModel {
/**
* feed refresh is disabled until this date
*/
@Temporal(TemporalType.TIMESTAMP)
private Date disabledUntil;
@Column
private Instant disabledUntil;
/**
* http header returned by the feed

View File

@@ -1,6 +1,6 @@
package com.commafeed.backend.model;
import java.util.Date;
import java.time.Instant;
import java.util.Set;
import jakarta.persistence.CascadeType;
@@ -11,8 +11,6 @@ import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.OneToMany;
import jakarta.persistence.Table;
import jakarta.persistence.Temporal;
import jakarta.persistence.TemporalType;
import lombok.Getter;
import lombok.Setter;
@@ -39,11 +37,11 @@ public class FeedEntry extends AbstractModel {
@Column(length = 2048)
private String url;
@Temporal(TemporalType.TIMESTAMP)
private Date inserted;
@Column
private Instant inserted;
@Temporal(TemporalType.TIMESTAMP)
private Date updated;
@Column
private Instant updated;
@OneToMany(mappedBy = "entry", cascade = CascadeType.REMOVE)
private Set<FeedEntryStatus> statuses;

View File

@@ -1,7 +1,7 @@
package com.commafeed.backend.model;
import java.time.Instant;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import jakarta.persistence.Column;
@@ -10,8 +10,6 @@ import jakarta.persistence.FetchType;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.Table;
import jakarta.persistence.Temporal;
import jakarta.persistence.TemporalType;
import jakarta.persistence.Transient;
import lombok.Getter;
import lombok.Setter;
@@ -49,11 +47,11 @@ public class FeedEntryStatus extends AbstractModel {
@JoinColumn(nullable = false)
private User user;
@Temporal(TemporalType.TIMESTAMP)
private Date entryInserted;
@Column
private Instant entryInserted;
@Temporal(TemporalType.TIMESTAMP)
private Date entryUpdated;
@Column
private Instant entryUpdated;
public FeedEntryStatus() {

View File

@@ -1,12 +1,10 @@
package com.commafeed.backend.model;
import java.util.Date;
import java.time.Instant;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.Table;
import jakarta.persistence.Temporal;
import jakarta.persistence.TemporalType;
import lombok.Getter;
import lombok.Setter;
@@ -35,15 +33,15 @@ public class User extends AbstractModel {
@Column(nullable = false)
private boolean disabled;
@Temporal(TemporalType.TIMESTAMP)
private Date lastLogin;
@Column
private Instant lastLogin;
@Temporal(TemporalType.TIMESTAMP)
private Date created;
@Column
private Instant created;
@Column(length = 40)
private String recoverPasswordToken;
@Temporal(TemporalType.TIMESTAMP)
private Date recoverPasswordTokenDate;
@Column
private Instant recoverPasswordTokenDate;
}

View File

@@ -1,6 +1,6 @@
package com.commafeed.backend.service;
import java.util.Date;
import java.time.Instant;
import java.util.List;
import com.codahale.metrics.Meter;
@@ -106,7 +106,7 @@ public class DatabaseCleaningService {
log.info("cleanup done: {} entries for feeds exceeding capacity deleted", total);
}
public void cleanEntriesOlderThan(final Date olderThan) {
public void cleanEntriesOlderThan(final Instant olderThan) {
log.info("cleaning old entries");
long total = 0;
long deleted;
@@ -119,7 +119,7 @@ public class DatabaseCleaningService {
log.info("cleanup done: {} old entries deleted", total);
}
public void cleanStatusesOlderThan(final Date olderThan) {
public void cleanStatusesOlderThan(final Instant olderThan) {
log.info("cleaning old read statuses");
long total = 0;
long deleted;

View File

@@ -1,6 +1,6 @@
package com.commafeed.backend.service;
import java.util.Date;
import java.time.Instant;
import java.util.List;
import org.apache.commons.codec.digest.DigestUtils;
@@ -73,7 +73,7 @@ public class FeedEntryService {
entry.setGuidHash(guidHash);
entry.setUrl(FeedUtils.truncate(e.url(), 2048));
entry.setUpdated(e.updated());
entry.setInserted(new Date());
entry.setInserted(Instant.now());
entry.setFeed(feed);
entry.setContent(feedEntryContentService.findOrCreate(e.content(), feed.getLink()));
@@ -117,7 +117,7 @@ public class FeedEntryService {
feedEntryStatusDAO.saveOrUpdate(status);
}
public void markSubscriptionEntries(User user, List<FeedSubscription> subscriptions, Date olderThan, Date insertedBefore,
public void markSubscriptionEntries(User user, List<FeedSubscription> subscriptions, Instant olderThan, Instant insertedBefore,
List<FeedEntryKeyword> keywords) {
List<FeedEntryStatus> statuses = feedEntryStatusDAO.findBySubscriptions(user, subscriptions, true, keywords, null, -1, -1, null,
false, false, null, null, null);
@@ -126,18 +126,18 @@ public class FeedEntryService {
cache.invalidateUserRootCategory(user);
}
public void markStarredEntries(User user, Date olderThan, Date insertedBefore) {
public void markStarredEntries(User user, Instant olderThan, Instant insertedBefore) {
List<FeedEntryStatus> statuses = feedEntryStatusDAO.findStarred(user, null, -1, -1, null, false);
markList(statuses, olderThan, insertedBefore);
}
private void markList(List<FeedEntryStatus> statuses, Date olderThan, Date insertedBefore) {
private void markList(List<FeedEntryStatus> statuses, Instant olderThan, Instant insertedBefore) {
List<FeedEntryStatus> statusesToMark = statuses.stream().filter(s -> {
Date entryDate = s.getEntry().getUpdated();
return olderThan == null || entryDate == null || entryDate.before(olderThan);
Instant entryDate = s.getEntry().getUpdated();
return olderThan == null || entryDate == null || entryDate.isBefore(olderThan);
}).filter(s -> {
Date insertedDate = s.getEntry().getInserted();
return insertedBefore == null || insertedDate == null || insertedDate.before(insertedBefore);
Instant insertedDate = s.getEntry().getInserted();
return insertedBefore == null || insertedDate == null || insertedDate.isBefore(insertedBefore);
}).toList();
statusesToMark.forEach(s -> s.setRead(true));

View File

@@ -1,7 +1,7 @@
package com.commafeed.backend.service;
import java.io.IOException;
import java.util.Date;
import java.time.Instant;
import java.util.Set;
import org.apache.commons.codec.digest.DigestUtils;
@@ -45,7 +45,7 @@ public class FeedService {
feed.setUrl(url);
feed.setNormalizedUrl(normalizedUrl);
feed.setNormalizedUrlHash(normalizedUrlHash);
feed.setDisabledUntil(new Date(0));
feed.setDisabledUntil(Instant.EPOCH);
feedDAO.saveOrUpdate(feed);
}
return feed;
@@ -55,7 +55,7 @@ public class FeedService {
String normalized = FeedUtils.normalizeURL(feed.getUrl());
feed.setNormalizedUrl(normalized);
feed.setNormalizedUrlHash(DigestUtils.sha1Hex(normalized));
feed.setLastUpdated(new Date());
feed.setLastUpdated(Instant.now());
feed.setEtagHeader(FeedUtils.truncate(feed.getEtagHeader(), 255));
feedDAO.saveOrUpdate(feed);
}

View File

@@ -1,6 +1,6 @@
package com.commafeed.backend.service;
import java.util.Date;
import java.time.Instant;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@@ -110,8 +110,8 @@ public class FeedSubscriptionService {
public void refreshAllUpForRefresh(User user) {
List<FeedSubscription> subs = feedSubscriptionDAO.findAll(user);
for (FeedSubscription sub : subs) {
Date disabledUntil = sub.getFeed().getDisabledUntil();
if (disabledUntil == null || disabledUntil.before(new Date())) {
Instant disabledUntil = sub.getFeed().getDisabledUntil();
if (disabledUntil == null || disabledUntil.isBefore(Instant.now())) {
Feed feed = sub.getFeed();
feedRefreshEngine.refreshImmediately(feed);
}

View File

@@ -1,9 +1,9 @@
package com.commafeed.backend.service;
import java.time.Instant;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Date;
import java.util.Optional;
import java.util.Set;
import java.util.UUID;
@@ -130,7 +130,7 @@ public class UserService {
byte[] salt = encryptionService.generateSalt();
user.setName(name);
user.setEmail(email);
user.setCreated(new Date());
user.setCreated(Instant.now());
user.setSalt(salt);
user.setPassword(encryptionService.getEncryptedPassword(password, salt));
userDAO.saveOrUpdate(user);

View File

@@ -1,8 +1,7 @@
package com.commafeed.backend.service.internal;
import java.util.Date;
import org.apache.commons.lang3.time.DateUtils;
import java.time.Instant;
import java.time.temporal.ChronoUnit;
import com.commafeed.CommaFeedConfiguration;
import com.commafeed.backend.dao.UnitOfWork;
@@ -25,9 +24,9 @@ public class PostLoginActivities {
public void executeFor(User user) {
// only update lastLogin every once in a while in order to avoid invalidating the cache every time someone logs in
Date now = new Date();
Date lastLogin = user.getLastLogin();
if (lastLogin == null || lastLogin.before(DateUtils.addMinutes(now, -30))) {
Instant now = Instant.now();
Instant lastLogin = user.getLastLogin();
if (lastLogin == null || ChronoUnit.MINUTES.between(lastLogin, now) >= 30) {
user.setLastLogin(now);
boolean heavyLoad = Boolean.TRUE.equals(config.getApplicationSettings().getHeavyLoad());

View File

@@ -1,10 +1,9 @@
package com.commafeed.backend.task;
import java.util.Date;
import java.time.Duration;
import java.time.Instant;
import java.util.concurrent.TimeUnit;
import org.apache.commons.lang3.time.DateUtils;
import com.commafeed.CommaFeedConfiguration;
import com.commafeed.backend.service.DatabaseCleaningService;
@@ -23,7 +22,7 @@ public class OldEntriesCleanupTask extends ScheduledTask {
public void run() {
int maxAgeDays = config.getApplicationSettings().getMaxEntriesAgeDays();
if (maxAgeDays > 0) {
Date threshold = DateUtils.addDays(new Date(), -1 * maxAgeDays);
Instant threshold = Instant.now().minus(Duration.ofDays(maxAgeDays));
cleaner.cleanEntriesOlderThan(threshold);
}
}

View File

@@ -1,6 +1,6 @@
package com.commafeed.backend.task;
import java.util.Date;
import java.time.Instant;
import java.util.concurrent.TimeUnit;
import com.commafeed.CommaFeedConfiguration;
@@ -19,7 +19,7 @@ public class OldStatusesCleanupTask extends ScheduledTask {
@Override
public void run() {
Date threshold = config.getApplicationSettings().getUnreadThreshold();
Instant threshold = config.getApplicationSettings().getUnreadThreshold();
if (threshold != null) {
cleaner.cleanStatusesOlderThan(threshold);
}