mirror of
https://github.com/Athou/commafeed.git
synced 2026-03-21 21:37:29 +00:00
revamp cache service
This commit is contained in:
@@ -33,6 +33,8 @@ import com.commafeed.backend.model.FeedSubscription;
|
||||
import com.commafeed.backend.model.User;
|
||||
import com.commafeed.backend.model.UserRole.Role;
|
||||
import com.commafeed.backend.model.UserSettings.ReadingOrder;
|
||||
import com.commafeed.backend.services.FeedCategoryService;
|
||||
import com.commafeed.backend.services.FeedEntryService;
|
||||
import com.commafeed.backend.services.FeedSubscriptionService;
|
||||
import com.commafeed.frontend.SecurityCheck;
|
||||
import com.commafeed.frontend.model.Category;
|
||||
@@ -68,6 +70,9 @@ public class CategoryREST extends AbstractResourceREST {
|
||||
@Inject
|
||||
FeedEntryStatusDAO feedEntryStatusDAO;
|
||||
|
||||
@Inject
|
||||
FeedEntryService feedEntryService;
|
||||
|
||||
@Inject
|
||||
FeedCategoryDAO feedCategoryDAO;
|
||||
|
||||
@@ -77,6 +82,9 @@ public class CategoryREST extends AbstractResourceREST {
|
||||
@Inject
|
||||
FeedSubscriptionService feedSubscriptionService;
|
||||
|
||||
@Inject
|
||||
FeedCategoryService feedCategoryService;
|
||||
|
||||
@Inject
|
||||
CacheService cache;
|
||||
|
||||
@@ -206,17 +214,16 @@ public class CategoryREST extends AbstractResourceREST {
|
||||
Date olderThan = req.getOlderThan() == null ? null : new Date(req.getOlderThan());
|
||||
|
||||
if (ALL.equals(req.getId())) {
|
||||
List<FeedSubscription> subscriptions = feedSubscriptionDAO.findAll(getUser());
|
||||
feedEntryStatusDAO.markSubscriptionEntries(subscriptions, olderThan);
|
||||
List<FeedSubscription> subscriptions = feedSubscriptionService.getSubscriptions(getUser());
|
||||
feedEntryService.markSubscriptionEntries(subscriptions, olderThan);
|
||||
} else if (STARRED.equals(req.getId())) {
|
||||
feedEntryStatusDAO.markStarredEntries(getUser(), olderThan);
|
||||
feedEntryService.markStarredEntries(getUser(), olderThan);
|
||||
} else {
|
||||
FeedCategory parent = feedCategoryDAO.findById(getUser(), Long.valueOf(req.getId()));
|
||||
List<FeedCategory> categories = feedCategoryDAO.findAllChildrenCategories(getUser(), parent);
|
||||
List<FeedSubscription> subs = feedSubscriptionDAO.findByCategories(getUser(), categories);
|
||||
feedEntryStatusDAO.markSubscriptionEntries(subs, olderThan);
|
||||
feedEntryService.markSubscriptionEntries(subs, olderThan);
|
||||
}
|
||||
cache.invalidateUserData(getUser());
|
||||
return Response.ok(Status.OK).build();
|
||||
}
|
||||
|
||||
@@ -238,7 +245,7 @@ public class CategoryREST extends AbstractResourceREST {
|
||||
cat.setParent(parent);
|
||||
}
|
||||
feedCategoryDAO.saveOrUpdate(cat);
|
||||
cache.invalidateUserData(getUser());
|
||||
cache.invalidateUserCategories(getUser());
|
||||
return Response.ok().build();
|
||||
}
|
||||
|
||||
@@ -266,7 +273,7 @@ public class CategoryREST extends AbstractResourceREST {
|
||||
feedCategoryDAO.saveOrUpdate(categories);
|
||||
|
||||
feedCategoryDAO.delete(cat);
|
||||
cache.invalidateUserData(getUser());
|
||||
cache.invalidateUserCategories(getUser());
|
||||
return Response.ok().build();
|
||||
} else {
|
||||
return Response.status(Status.NOT_FOUND).build();
|
||||
@@ -322,7 +329,7 @@ public class CategoryREST extends AbstractResourceREST {
|
||||
}
|
||||
|
||||
feedCategoryDAO.saveOrUpdate(category);
|
||||
cache.invalidateUserData(getUser());
|
||||
cache.invalidateUserCategories(getUser());
|
||||
return Response.ok(Status.OK).build();
|
||||
}
|
||||
|
||||
@@ -339,7 +346,7 @@ public class CategoryREST extends AbstractResourceREST {
|
||||
}
|
||||
category.setCollapsed(req.isCollapse());
|
||||
feedCategoryDAO.saveOrUpdate(category);
|
||||
cache.invalidateUserData(getUser());
|
||||
cache.invalidateUserCategories(getUser());
|
||||
return Response.ok(Status.OK).build();
|
||||
}
|
||||
|
||||
@@ -364,18 +371,15 @@ public class CategoryREST extends AbstractResourceREST {
|
||||
public Response getSubscriptions() {
|
||||
User user = getUser();
|
||||
|
||||
Category root = cache.getRootCategory(user);
|
||||
if (root == null) {
|
||||
log.debug("root category cache miss for {}", user.getName());
|
||||
List<FeedCategory> categories = feedCategoryDAO.findAll(user);
|
||||
List<FeedSubscription> subscriptions = feedSubscriptionDAO.findAll(getUser());
|
||||
Map<Long, Long> unreadCount = feedSubscriptionService.getUnreadCount(getUser());
|
||||
Category root = null;
|
||||
List<FeedCategory> categories = feedCategoryService.getCategories(user);
|
||||
List<FeedSubscription> subscriptions = feedSubscriptionService.getSubscriptions(getUser());
|
||||
Map<Long, Long> unreadCount = feedSubscriptionService.getUnreadCount(getUser());
|
||||
|
||||
root = buildCategory(null, categories, subscriptions, unreadCount);
|
||||
root.setId("all");
|
||||
root.setName("All");
|
||||
|
||||
root = buildCategory(null, categories, subscriptions, unreadCount);
|
||||
root.setId("all");
|
||||
root.setName("All");
|
||||
cache.setRootCategory(user, root);
|
||||
}
|
||||
return Response.ok(root).build();
|
||||
}
|
||||
|
||||
|
||||
@@ -13,7 +13,6 @@ import javax.ws.rs.core.Response.Status;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
|
||||
import com.commafeed.backend.cache.CacheService;
|
||||
import com.commafeed.backend.dao.FeedEntryStatusDAO;
|
||||
import com.commafeed.backend.dao.FeedSubscriptionDAO;
|
||||
import com.commafeed.backend.model.FeedEntryStatus;
|
||||
@@ -44,9 +43,6 @@ public class EntryREST extends AbstractResourceREST {
|
||||
@Inject
|
||||
FeedSubscriptionDAO feedSubscriptionDAO;
|
||||
|
||||
@Inject
|
||||
CacheService cache;
|
||||
|
||||
@Path("/mark")
|
||||
@POST
|
||||
@ApiOperation(value = "Mark a feed entry", notes = "Mark a feed entry as read/unread")
|
||||
@@ -56,7 +52,6 @@ public class EntryREST extends AbstractResourceREST {
|
||||
Preconditions.checkNotNull(req.getFeedId());
|
||||
|
||||
feedEntryService.markEntry(getUser(), Long.valueOf(req.getId()), req.getFeedId(), req.isRead());
|
||||
cache.invalidateUserData(getUser());
|
||||
return Response.ok(Status.OK).build();
|
||||
}
|
||||
|
||||
|
||||
@@ -55,6 +55,7 @@ import com.commafeed.backend.model.FeedEntryStatus;
|
||||
import com.commafeed.backend.model.FeedSubscription;
|
||||
import com.commafeed.backend.model.UserRole.Role;
|
||||
import com.commafeed.backend.model.UserSettings.ReadingOrder;
|
||||
import com.commafeed.backend.services.FeedEntryService;
|
||||
import com.commafeed.backend.services.FeedSubscriptionService;
|
||||
import com.commafeed.frontend.SecurityCheck;
|
||||
import com.commafeed.frontend.model.Entries;
|
||||
@@ -97,6 +98,9 @@ public class FeedREST extends AbstractResourceREST {
|
||||
@Inject
|
||||
FeedSubscriptionDAO feedSubscriptionDAO;
|
||||
|
||||
@Inject
|
||||
FeedEntryService feedEntryService;
|
||||
|
||||
@Inject
|
||||
FeedSubscriptionService feedSubscriptionService;
|
||||
|
||||
@@ -274,9 +278,8 @@ public class FeedREST extends AbstractResourceREST {
|
||||
|
||||
FeedSubscription subscription = feedSubscriptionDAO.findById(getUser(), Long.valueOf(req.getId()));
|
||||
if (subscription != null) {
|
||||
feedEntryStatusDAO.markSubscriptionEntries(Arrays.asList(subscription), olderThan);
|
||||
feedEntryService.markSubscriptionEntries(Arrays.asList(subscription), olderThan);
|
||||
}
|
||||
cache.invalidateUserData(getUser());
|
||||
return Response.ok(Status.OK).build();
|
||||
}
|
||||
|
||||
@@ -353,7 +356,6 @@ public class FeedREST extends AbstractResourceREST {
|
||||
log.info("Failed to subscribe to URL {}: {}", url, e.getMessage());
|
||||
return Response.status(Status.SERVICE_UNAVAILABLE).entity("Failed to subscribe to URL " + url + ": " + e.getMessage()).build();
|
||||
}
|
||||
cache.invalidateUserData(getUser());
|
||||
return Response.ok(Status.OK).build();
|
||||
}
|
||||
|
||||
@@ -390,10 +392,8 @@ public class FeedREST extends AbstractResourceREST {
|
||||
Preconditions.checkNotNull(req);
|
||||
Preconditions.checkNotNull(req.getId());
|
||||
|
||||
FeedSubscription sub = feedSubscriptionDAO.findById(getUser(), req.getId());
|
||||
if (sub != null) {
|
||||
feedSubscriptionDAO.delete(sub);
|
||||
cache.invalidateUserData(getUser());
|
||||
boolean deleted = feedSubscriptionService.unsubscribe(getUser(), req.getId());
|
||||
if (deleted) {
|
||||
return Response.ok(Status.OK).build();
|
||||
} else {
|
||||
return Response.status(Status.NOT_FOUND).build();
|
||||
@@ -446,7 +446,7 @@ public class FeedREST extends AbstractResourceREST {
|
||||
} else {
|
||||
feedSubscriptionDAO.saveOrUpdate(subscription);
|
||||
}
|
||||
cache.invalidateUserData(getUser());
|
||||
cache.invalidateUserSubscriptions(getUser());
|
||||
return Response.ok(Status.OK).build();
|
||||
}
|
||||
|
||||
@@ -480,7 +480,6 @@ public class FeedREST extends AbstractResourceREST {
|
||||
} catch (Exception e) {
|
||||
throw new WebApplicationException(Response.status(Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build());
|
||||
}
|
||||
cache.invalidateUserData(getUser());
|
||||
return Response.temporaryRedirect(URI.create(applicationSettingsService.get().getPublicUrl())).build();
|
||||
}
|
||||
|
||||
|
||||
@@ -12,7 +12,6 @@ import javax.ws.rs.core.Response.Status;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
|
||||
import com.commafeed.backend.StartupBean;
|
||||
import com.commafeed.backend.cache.CacheService;
|
||||
import com.commafeed.backend.dao.UserDAO;
|
||||
import com.commafeed.backend.dao.UserRoleDAO;
|
||||
import com.commafeed.backend.dao.UserSettingsDAO;
|
||||
@@ -58,9 +57,6 @@ public class UserREST extends AbstractResourceREST {
|
||||
@Inject
|
||||
PasswordEncryptionService encryptionService;
|
||||
|
||||
@Inject
|
||||
CacheService cache;
|
||||
|
||||
@Inject
|
||||
ApplicationSettingsService applicationSettingsService;
|
||||
|
||||
@@ -200,7 +196,6 @@ public class UserREST extends AbstractResourceREST {
|
||||
return Response.status(Status.FORBIDDEN).build();
|
||||
}
|
||||
userService.unregister(getUser());
|
||||
cache.invalidateUserData(getUser());
|
||||
return Response.ok().build();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user