mirror of
https://github.com/Athou/commafeed.git
synced 2026-03-21 21:37:29 +00:00
cache the "tree"
This commit is contained in:
@@ -23,12 +23,14 @@ import org.apache.commons.lang.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.commafeed.backend.cache.CacheService;
|
||||
import com.commafeed.backend.dao.FeedCategoryDAO;
|
||||
import com.commafeed.backend.dao.FeedEntryStatusDAO;
|
||||
import com.commafeed.backend.dao.FeedSubscriptionDAO;
|
||||
import com.commafeed.backend.model.FeedCategory;
|
||||
import com.commafeed.backend.model.FeedEntryStatus;
|
||||
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.frontend.SecurityCheck;
|
||||
@@ -71,6 +73,9 @@ public class CategoryREST extends AbstractResourceREST {
|
||||
@Inject
|
||||
FeedSubscriptionDAO feedSubscriptionDAO;
|
||||
|
||||
@Inject
|
||||
CacheService cache;
|
||||
|
||||
@Path("/entries")
|
||||
@GET
|
||||
@ApiOperation(value = "Get category entries", notes = "Get a list of category entries", responseClass = "com.commafeed.frontend.model.Entries")
|
||||
@@ -226,7 +231,7 @@ public class CategoryREST extends AbstractResourceREST {
|
||||
feedEntryStatusDAO.markCategoryEntries(getUser(), categories,
|
||||
olderThan);
|
||||
}
|
||||
|
||||
cache.invalidateRootCategory(getUser());
|
||||
return Response.ok(Status.OK).build();
|
||||
}
|
||||
|
||||
@@ -249,6 +254,7 @@ public class CategoryREST extends AbstractResourceREST {
|
||||
cat.setParent(parent);
|
||||
}
|
||||
feedCategoryDAO.saveOrUpdate(cat);
|
||||
cache.invalidateRootCategory(getUser());
|
||||
return Response.ok().build();
|
||||
}
|
||||
|
||||
@@ -279,6 +285,7 @@ public class CategoryREST extends AbstractResourceREST {
|
||||
feedCategoryDAO.saveOrUpdate(categories);
|
||||
|
||||
feedCategoryDAO.delete(cat);
|
||||
cache.invalidateRootCategory(getUser());
|
||||
return Response.ok().build();
|
||||
} else {
|
||||
return Response.status(Status.NOT_FOUND).build();
|
||||
@@ -343,7 +350,7 @@ public class CategoryREST extends AbstractResourceREST {
|
||||
}
|
||||
|
||||
feedCategoryDAO.saveOrUpdate(category);
|
||||
|
||||
cache.invalidateRootCategory(getUser());
|
||||
return Response.ok(Status.OK).build();
|
||||
}
|
||||
|
||||
@@ -361,7 +368,7 @@ public class CategoryREST extends AbstractResourceREST {
|
||||
}
|
||||
category.setCollapsed(req.isCollapse());
|
||||
feedCategoryDAO.saveOrUpdate(category);
|
||||
|
||||
cache.invalidateRootCategory(getUser());
|
||||
return Response.ok(Status.OK).build();
|
||||
}
|
||||
|
||||
@@ -382,18 +389,23 @@ public class CategoryREST extends AbstractResourceREST {
|
||||
@Path("/get")
|
||||
@ApiOperation(value = "Get feed categories", notes = "Get all categories and subscriptions of the user", responseClass = "com.commafeed.frontend.model.Category")
|
||||
public Response getSubscriptions() {
|
||||
User user = getUser();
|
||||
|
||||
List<FeedCategory> categories = feedCategoryDAO.findAll(getUser());
|
||||
List<FeedSubscription> subscriptions = feedSubscriptionDAO
|
||||
.findAll(getUser());
|
||||
Map<Long, Long> unreadCount = feedEntryStatusDAO
|
||||
.getUnreadCount(getUser());
|
||||
|
||||
Category root = buildCategory(null, categories, subscriptions,
|
||||
unreadCount);
|
||||
root.setId("all");
|
||||
root.setName("All");
|
||||
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 = feedEntryStatusDAO
|
||||
.getUnreadCount(getUser());
|
||||
|
||||
root = buildCategory(null, categories, subscriptions,
|
||||
unreadCount);
|
||||
root.setId("all");
|
||||
root.setName("All");
|
||||
cache.setRootCategory(user, root);
|
||||
}
|
||||
return Response.ok(root).build();
|
||||
}
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@ 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.model.FeedEntryStatus;
|
||||
import com.commafeed.backend.services.FeedEntryService;
|
||||
@@ -36,6 +37,9 @@ public class EntryREST extends AbstractResourceREST {
|
||||
@Inject
|
||||
FeedEntryStatusDAO feedEntryStatusDAO;
|
||||
|
||||
@Inject
|
||||
CacheService cache;
|
||||
|
||||
@Path("/mark")
|
||||
@POST
|
||||
@ApiOperation(value = "Mark a feed entry", notes = "Mark a feed entry as read/unread")
|
||||
@@ -47,7 +51,7 @@ public class EntryREST extends AbstractResourceREST {
|
||||
|
||||
feedEntryService.markEntry(getUser(), Long.valueOf(req.getId()),
|
||||
req.getFeedId(), req.isRead());
|
||||
|
||||
cache.invalidateRootCategory(getUser());
|
||||
return Response.ok(Status.OK).build();
|
||||
}
|
||||
|
||||
|
||||
@@ -37,6 +37,7 @@ import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.commafeed.backend.StartupBean;
|
||||
import com.commafeed.backend.cache.CacheService;
|
||||
import com.commafeed.backend.dao.FeedCategoryDAO;
|
||||
import com.commafeed.backend.dao.FeedEntryStatusDAO;
|
||||
import com.commafeed.backend.dao.FeedSubscriptionDAO;
|
||||
@@ -112,6 +113,9 @@ public class FeedREST extends AbstractResourceREST {
|
||||
@Inject
|
||||
OPMLExporter opmlExporter;
|
||||
|
||||
@Inject
|
||||
CacheService cache;
|
||||
|
||||
@Context
|
||||
private HttpServletRequest request;
|
||||
|
||||
@@ -288,7 +292,7 @@ public class FeedREST extends AbstractResourceREST {
|
||||
if (subscription != null) {
|
||||
feedEntryStatusDAO.markSubscriptionEntries(subscription, olderThan);
|
||||
}
|
||||
|
||||
cache.invalidateRootCategory(getUser());
|
||||
return Response.ok(Status.OK).build();
|
||||
}
|
||||
|
||||
@@ -375,6 +379,7 @@ public class FeedREST extends AbstractResourceREST {
|
||||
.entity("Failed to subscribe to URL " + url + ": "
|
||||
+ e.getMessage()).build();
|
||||
}
|
||||
cache.invalidateRootCategory(getUser());
|
||||
return Response.ok(Status.OK).build();
|
||||
}
|
||||
|
||||
@@ -419,6 +424,7 @@ public class FeedREST extends AbstractResourceREST {
|
||||
req.getId());
|
||||
if (sub != null) {
|
||||
feedSubscriptionDAO.delete(sub);
|
||||
cache.invalidateRootCategory(getUser());
|
||||
return Response.ok(Status.OK).build();
|
||||
} else {
|
||||
return Response.status(Status.NOT_FOUND).build();
|
||||
@@ -478,7 +484,7 @@ public class FeedREST extends AbstractResourceREST {
|
||||
} else {
|
||||
feedSubscriptionDAO.saveOrUpdate(subscription);
|
||||
}
|
||||
|
||||
cache.invalidateRootCategory(getUser());
|
||||
return Response.ok(Status.OK).build();
|
||||
}
|
||||
|
||||
@@ -517,6 +523,7 @@ public class FeedREST extends AbstractResourceREST {
|
||||
.status(Status.INTERNAL_SERVER_ERROR)
|
||||
.entity(e.getMessage()).build());
|
||||
}
|
||||
cache.invalidateRootCategory(getUser());
|
||||
return Response.temporaryRedirect(
|
||||
URI.create(applicationSettingsService.get().getPublicUrl()))
|
||||
.build();
|
||||
|
||||
@@ -12,6 +12,7 @@ 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;
|
||||
@@ -56,6 +57,9 @@ public class UserREST extends AbstractResourceREST {
|
||||
@Inject
|
||||
PasswordEncryptionService encryptionService;
|
||||
|
||||
@Inject
|
||||
CacheService cache;
|
||||
|
||||
@Path("/settings")
|
||||
@GET
|
||||
@ApiOperation(value = "Retrieve user settings", notes = "Retrieve user settings", responseClass = "com.commafeed.frontend.model.Settings")
|
||||
@@ -194,6 +198,7 @@ public class UserREST extends AbstractResourceREST {
|
||||
return Response.status(Status.FORBIDDEN).build();
|
||||
}
|
||||
userService.unregister(getUser());
|
||||
cache.invalidateRootCategory(getUser());
|
||||
return Response.ok().build();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user