mirror of
https://github.com/Athou/commafeed.git
synced 2026-09-24 13:05:38 +00:00
migrate from java.util.Date to java.time
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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));
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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());
|
||||
|
||||
Reference in New Issue
Block a user