forked from Archives/Athou_commafeed
the feed refresh engine is now fast enough, it doesn't need workarounds anymore
This commit is contained in:
@@ -3,11 +3,9 @@ package com.commafeed.backend.service.internal;
|
|||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
import java.time.temporal.ChronoUnit;
|
import java.time.temporal.ChronoUnit;
|
||||||
|
|
||||||
import com.commafeed.CommaFeedConfiguration;
|
|
||||||
import com.commafeed.backend.dao.UnitOfWork;
|
import com.commafeed.backend.dao.UnitOfWork;
|
||||||
import com.commafeed.backend.dao.UserDAO;
|
import com.commafeed.backend.dao.UserDAO;
|
||||||
import com.commafeed.backend.model.User;
|
import com.commafeed.backend.model.User;
|
||||||
import com.commafeed.backend.service.FeedSubscriptionService;
|
|
||||||
|
|
||||||
import jakarta.inject.Inject;
|
import jakarta.inject.Inject;
|
||||||
import jakarta.inject.Singleton;
|
import jakarta.inject.Singleton;
|
||||||
@@ -18,9 +16,7 @@ import lombok.RequiredArgsConstructor;
|
|||||||
public class PostLoginActivities {
|
public class PostLoginActivities {
|
||||||
|
|
||||||
private final UserDAO userDAO;
|
private final UserDAO userDAO;
|
||||||
private final FeedSubscriptionService feedSubscriptionService;
|
|
||||||
private final UnitOfWork unitOfWork;
|
private final UnitOfWork unitOfWork;
|
||||||
private final CommaFeedConfiguration config;
|
|
||||||
|
|
||||||
public void executeFor(User user) {
|
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
|
// only update lastLogin every once in a while in order to avoid invalidating the cache every time someone logs in
|
||||||
@@ -28,19 +24,6 @@ public class PostLoginActivities {
|
|||||||
Instant lastLogin = user.getLastLogin();
|
Instant lastLogin = user.getLastLogin();
|
||||||
if (lastLogin == null || ChronoUnit.MINUTES.between(lastLogin, now) >= 30) {
|
if (lastLogin == null || ChronoUnit.MINUTES.between(lastLogin, now) >= 30) {
|
||||||
user.setLastLogin(now);
|
user.setLastLogin(now);
|
||||||
|
|
||||||
boolean heavyLoad = Boolean.TRUE.equals(config.getApplicationSettings().getHeavyLoad());
|
|
||||||
if (heavyLoad) {
|
|
||||||
// the amount of feeds in the database that are up for refresh might be very large since we're in heavy load mode
|
|
||||||
// the feed refresh engine might not be able to catch up quickly enough
|
|
||||||
// put feeds from online users that are up for refresh at the top of the queue
|
|
||||||
feedSubscriptionService.refreshAllUpForRefresh(user);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Post login activites are susceptible to run for any webservice call.
|
|
||||||
// We update the user in a new transaction to update the user immediately.
|
|
||||||
// If we didn't and the webservice call takes time, subsequent webservice calls would have to wait for the first call to
|
|
||||||
// finish even if they didn't use the same database tables, because they updated the user too.
|
|
||||||
unitOfWork.run(() -> userDAO.saveOrUpdate(user));
|
unitOfWork.run(() -> userDAO.saveOrUpdate(user));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user