forked from Archives/Athou_commafeed
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)
|
@Column(length = 32, nullable = false, unique = true)
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
@Column(length = 255, unique = true)
|
@Column(length = 255, unique = true)
|
||||||
private String email;
|
private String email;
|
||||||
|
|
||||||
@@ -66,4 +66,8 @@ public class User extends AbstractModel {
|
|||||||
@OneToMany(mappedBy = "user", fetch = FetchType.LAZY, cascade = CascadeType.REMOVE)
|
@OneToMany(mappedBy = "user", fetch = FetchType.LAZY, cascade = CascadeType.REMOVE)
|
||||||
private Set<FeedSubscription> subscriptions;
|
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) {
|
public UnreadCount getUnreadCount(User user, FeedSubscription sub) {
|
||||||
UnreadCount count = cache.getUnreadCount(sub);
|
UnreadCount count = cache.getUnreadCount(sub);
|
||||||
if (count == null) {
|
if (count == null) {
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
package com.commafeed.frontend.rest.resources;
|
package com.commafeed.frontend.rest.resources;
|
||||||
|
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import javax.annotation.PostConstruct;
|
import javax.annotation.PostConstruct;
|
||||||
import javax.inject.Inject;
|
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;
|
||||||
import javax.ws.rs.core.Response.Status;
|
import javax.ws.rs.core.Response.Status;
|
||||||
|
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
import org.apache.wicket.ThreadContext;
|
import org.apache.wicket.ThreadContext;
|
||||||
import org.apache.wicket.authentication.IAuthenticationStrategy;
|
import org.apache.wicket.authentication.IAuthenticationStrategy;
|
||||||
import org.apache.wicket.authroles.authorization.strategies.role.Roles;
|
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.dao.UserDAO;
|
||||||
import com.commafeed.backend.model.User;
|
import com.commafeed.backend.model.User;
|
||||||
import com.commafeed.backend.model.UserRole.Role;
|
import com.commafeed.backend.model.UserRole.Role;
|
||||||
|
import com.commafeed.backend.services.FeedSubscriptionService;
|
||||||
import com.commafeed.frontend.CommaFeedApplication;
|
import com.commafeed.frontend.CommaFeedApplication;
|
||||||
import com.commafeed.frontend.CommaFeedSession;
|
import com.commafeed.frontend.CommaFeedSession;
|
||||||
import com.commafeed.frontend.SecurityCheck;
|
import com.commafeed.frontend.SecurityCheck;
|
||||||
@@ -35,6 +40,7 @@ import com.commafeed.frontend.SecurityCheck;
|
|||||||
@Produces(MediaType.APPLICATION_JSON)
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
@Consumes(MediaType.APPLICATION_JSON)
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
@SecurityCheck(Role.USER)
|
@SecurityCheck(Role.USER)
|
||||||
|
@Slf4j
|
||||||
public abstract class AbstractREST {
|
public abstract class AbstractREST {
|
||||||
|
|
||||||
@Context
|
@Context
|
||||||
@@ -49,6 +55,9 @@ public abstract class AbstractREST {
|
|||||||
@Inject
|
@Inject
|
||||||
private UserDAO userDAO;
|
private UserDAO userDAO;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
FeedSubscriptionService feedSubscriptionService;
|
||||||
|
|
||||||
@PostConstruct
|
@PostConstruct
|
||||||
public void init() {
|
public void init() {
|
||||||
CommaFeedApplication app = CommaFeedApplication.get();
|
CommaFeedApplication app = CommaFeedApplication.get();
|
||||||
@@ -98,6 +107,8 @@ public abstract class AbstractREST {
|
|||||||
|
|
||||||
@AroundInvoke
|
@AroundInvoke
|
||||||
public Object intercept(InvocationContext context) throws Exception {
|
public Object intercept(InvocationContext context) throws Exception {
|
||||||
|
startFullRefresh(getUser());
|
||||||
|
|
||||||
Method method = context.getMethod();
|
Method method = context.getMethod();
|
||||||
|
|
||||||
// check security
|
// check security
|
||||||
@@ -137,6 +148,19 @@ public abstract class AbstractREST {
|
|||||||
return result;
|
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) {
|
private boolean checkRole(Role requiredRole) {
|
||||||
if (requiredRole == Role.NONE) {
|
if (requiredRole == Role.NONE) {
|
||||||
return true;
|
return true;
|
||||||
@@ -146,4 +170,5 @@ public abstract class AbstractREST {
|
|||||||
boolean authorized = roles.hasAnyRole(new Roles(requiredRole.name()));
|
boolean authorized = roles.hasAnyRole(new Roles(requiredRole.name()));
|
||||||
return authorized;
|
return authorized;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -274,11 +274,7 @@ public class FeedREST extends AbstractREST {
|
|||||||
@GET
|
@GET
|
||||||
@ApiOperation(value = "Queue all feeds of the user for refresh", notes = "Manually add all feeds of the user to the refresh queue")
|
@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() {
|
public Response queueAllForRefresh() {
|
||||||
List<FeedSubscription> subs = feedSubscriptionDAO.findAll(getUser());
|
feedSubscriptionService.refreshAll(getUser());
|
||||||
for (FeedSubscription sub : subs) {
|
|
||||||
Feed feed = sub.getFeed();
|
|
||||||
taskGiver.add(feed, true);
|
|
||||||
}
|
|
||||||
return Response.ok().build();
|
return Response.ok().build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -42,4 +42,10 @@
|
|||||||
</createIndex>
|
</createIndex>
|
||||||
</changeSet>
|
</changeSet>
|
||||||
|
|
||||||
|
<changeSet author="athou" id="add-full-refresh-timestamp">
|
||||||
|
<addColumn tableName="USERS">
|
||||||
|
<column name="last_full_refresh" type="DATETIME" />
|
||||||
|
</addColumn>
|
||||||
|
</changeSet>
|
||||||
|
|
||||||
</databaseChangeLog>
|
</databaseChangeLog>
|
||||||
|
|||||||
Reference in New Issue
Block a user