mirror of
https://github.com/Athou/commafeed.git
synced 2026-03-21 21:37:29 +00:00
force a full refresh of the user's feeds when he logs in
This commit is contained in:
@@ -32,7 +32,7 @@ public class User extends AbstractModel {
|
||||
|
||||
@Column(length = 32, nullable = false, unique = true)
|
||||
private String name;
|
||||
|
||||
|
||||
@Column(length = 255, unique = true)
|
||||
private String email;
|
||||
|
||||
@@ -66,4 +66,8 @@ public class User extends AbstractModel {
|
||||
@OneToMany(mappedBy = "user", fetch = FetchType.LAZY, cascade = CascadeType.REMOVE)
|
||||
private Set<FeedSubscription> subscriptions;
|
||||
|
||||
@Column(name = "last_full_refresh")
|
||||
@Temporal(TemporalType.TIMESTAMP)
|
||||
private Date lastFullRefresh;
|
||||
|
||||
}
|
||||
|
||||
@@ -95,6 +95,14 @@ public class FeedSubscriptionService {
|
||||
}
|
||||
}
|
||||
|
||||
public void refreshAll(User user) {
|
||||
List<FeedSubscription> subs = feedSubscriptionDAO.findAll(user);
|
||||
for (FeedSubscription sub : subs) {
|
||||
Feed feed = sub.getFeed();
|
||||
taskGiver.add(feed, true);
|
||||
}
|
||||
}
|
||||
|
||||
public UnreadCount getUnreadCount(User user, FeedSubscription sub) {
|
||||
UnreadCount count = cache.getUnreadCount(sub);
|
||||
if (count == null) {
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package com.commafeed.frontend.rest.resources;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Date;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.inject.Inject;
|
||||
@@ -16,6 +18,8 @@ import javax.ws.rs.core.MediaType;
|
||||
import javax.ws.rs.core.Response;
|
||||
import javax.ws.rs.core.Response.Status;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import org.apache.wicket.ThreadContext;
|
||||
import org.apache.wicket.authentication.IAuthenticationStrategy;
|
||||
import org.apache.wicket.authroles.authorization.strategies.role.Roles;
|
||||
@@ -28,6 +32,7 @@ import com.codahale.metrics.MetricRegistry;
|
||||
import com.commafeed.backend.dao.UserDAO;
|
||||
import com.commafeed.backend.model.User;
|
||||
import com.commafeed.backend.model.UserRole.Role;
|
||||
import com.commafeed.backend.services.FeedSubscriptionService;
|
||||
import com.commafeed.frontend.CommaFeedApplication;
|
||||
import com.commafeed.frontend.CommaFeedSession;
|
||||
import com.commafeed.frontend.SecurityCheck;
|
||||
@@ -35,6 +40,7 @@ import com.commafeed.frontend.SecurityCheck;
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@SecurityCheck(Role.USER)
|
||||
@Slf4j
|
||||
public abstract class AbstractREST {
|
||||
|
||||
@Context
|
||||
@@ -49,6 +55,9 @@ public abstract class AbstractREST {
|
||||
@Inject
|
||||
private UserDAO userDAO;
|
||||
|
||||
@Inject
|
||||
FeedSubscriptionService feedSubscriptionService;
|
||||
|
||||
@PostConstruct
|
||||
public void init() {
|
||||
CommaFeedApplication app = CommaFeedApplication.get();
|
||||
@@ -98,6 +107,8 @@ public abstract class AbstractREST {
|
||||
|
||||
@AroundInvoke
|
||||
public Object intercept(InvocationContext context) throws Exception {
|
||||
startFullRefresh(getUser());
|
||||
|
||||
Method method = context.getMethod();
|
||||
|
||||
// check security
|
||||
@@ -137,6 +148,19 @@ public abstract class AbstractREST {
|
||||
return result;
|
||||
}
|
||||
|
||||
private void startFullRefresh(User user) {
|
||||
if (user == null)
|
||||
return;
|
||||
|
||||
Date now = new Date();
|
||||
if (user.getLastFullRefresh() == null || (now.getTime() - user.getLastFullRefresh().getTime()) > TimeUnit.MINUTES.toMillis(30)) {
|
||||
log.info("Starting full refresh for {}", user.getName());
|
||||
user.setLastFullRefresh(now);
|
||||
userDAO.saveOrUpdate(user);
|
||||
feedSubscriptionService.refreshAll(user);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean checkRole(Role requiredRole) {
|
||||
if (requiredRole == Role.NONE) {
|
||||
return true;
|
||||
@@ -146,4 +170,5 @@ public abstract class AbstractREST {
|
||||
boolean authorized = roles.hasAnyRole(new Roles(requiredRole.name()));
|
||||
return authorized;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -274,11 +274,7 @@ public class FeedREST extends AbstractREST {
|
||||
@GET
|
||||
@ApiOperation(value = "Queue all feeds of the user for refresh", notes = "Manually add all feeds of the user to the refresh queue")
|
||||
public Response queueAllForRefresh() {
|
||||
List<FeedSubscription> subs = feedSubscriptionDAO.findAll(getUser());
|
||||
for (FeedSubscription sub : subs) {
|
||||
Feed feed = sub.getFeed();
|
||||
taskGiver.add(feed, true);
|
||||
}
|
||||
feedSubscriptionService.refreshAll(getUser());
|
||||
return Response.ok().build();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user