From 56e3f36262f0d850c9ba60916c6ae6725a21d87c Mon Sep 17 00:00:00 2001 From: Athou Date: Sat, 6 Apr 2013 07:08:52 +0200 Subject: [PATCH] speed up mark all as read --- .../frontend/rest/resources/EntriesREST.java | 50 +++++++++++-------- 1 file changed, 29 insertions(+), 21 deletions(-) diff --git a/src/main/java/com/commafeed/frontend/rest/resources/EntriesREST.java b/src/main/java/com/commafeed/frontend/rest/resources/EntriesREST.java index e0941f3b..9d37cee8 100644 --- a/src/main/java/com/commafeed/frontend/rest/resources/EntriesREST.java +++ b/src/main/java/com/commafeed/frontend/rest/resources/EntriesREST.java @@ -172,32 +172,40 @@ public class EntriesREST extends AbstractREST { FeedEntry entry = feedEntryService.findById(Long.valueOf(id)); markEntry(entry, read); } else if (type == Type.feed) { - Feed feed = feedSubscriptionService.findById(Long.valueOf(id)) - .getFeed(); - List entries = feedEntryService.getEntries( - feed, getUser(), false); - for (FeedEntryWithStatus entry : entries) { - markEntry(entry, read); + if (read) { + Feed feed = feedSubscriptionService.findById(Long.valueOf(id)) + .getFeed(); + List entries = feedEntryService + .getEntries(feed, getUser(), true); + for (FeedEntryWithStatus entry : entries) { + markEntry(entry, read); + } + } else { + return Response.status(Status.FORBIDDEN) + .entity("Operation not supported").build(); } } else if (type == Type.category) { - List entries = null; + if (read) { + List entries = null; - if (ALL.equals(id)) { - entries = feedEntryService.getEntries(getUser(), false); + if (ALL.equals(id)) { + entries = feedEntryService.getEntries(getUser(), true); + } else { + FeedCategory feedCategory = feedCategoryService.findById( + getUser(), Long.valueOf(id)); + List childrenCategories = feedCategoryService + .findAllChildrenCategories(getUser(), feedCategory); + + entries = feedEntryService.getEntries(childrenCategories, + getUser(), true); + } + for (FeedEntryWithStatus entry : entries) { + markEntry(entry, read); + } } else { - FeedCategory feedCategory = feedCategoryService.findById( - getUser(), Long.valueOf(id)); - List childrenCategories = feedCategoryService - .findAllChildrenCategories(getUser(), feedCategory); - - entries = feedEntryService.getEntries(childrenCategories, - getUser(), false); + return Response.status(Status.FORBIDDEN) + .entity("Operation not supported").build(); } - - for (FeedEntryWithStatus entry : entries) { - markEntry(entry, true); - } - } return Response.ok(Status.OK).build(); }