refactored the way entries and statuses are fetched

This commit is contained in:
Athou
2013-07-19 11:17:19 +02:00
parent af274f797f
commit 079345b2e0
11 changed files with 362 additions and 395 deletions

View File

@@ -12,8 +12,10 @@ import org.apache.wicket.request.mapper.parameter.PageParameters;
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;
@@ -35,13 +37,16 @@ public class NextUnreadRedirectPage extends WebPage {
@Inject
FeedEntryStatusDAO feedEntryStatusDAO;
@Inject
FeedSubscriptionDAO feedSubscriptionDAO;
public NextUnreadRedirectPage(PageParameters params) {
String categoryId = params.get(PARAM_CATEGORYID).toString();
String orderParam = params.get(PARAM_READINGORDER).toString();
User user = CommaFeedSession.get().getUser();
ReadingOrder order = ReadingOrder.desc;
if (StringUtils.equals(orderParam, "asc")) {
order = ReadingOrder.asc;
}
@@ -49,16 +54,20 @@ public class NextUnreadRedirectPage extends WebPage {
List<FeedEntryStatus> statuses = null;
if (StringUtils.isBlank(categoryId)
|| CategoryREST.ALL.equals(categoryId)) {
statuses = feedEntryStatusDAO.findAllUnread(user, null, 0, 1,
order, true);
List<FeedSubscription> subscriptions = feedSubscriptionDAO
.findAll(user);
statuses = feedEntryStatusDAO.findBySubscriptions(subscriptions,
null, null, 0, 1, order, true);
} else {
FeedCategory category = feedCategoryDAO.findById(user,
Long.valueOf(categoryId));
if (category != null) {
List<FeedCategory> children = feedCategoryDAO
.findAllChildrenCategories(user, category);
statuses = feedEntryStatusDAO.findUnreadByCategories(children,
null, 0, 1, order, true);
List<FeedSubscription> subscriptions = feedSubscriptionDAO
.findByCategories(user, children);
statuses = feedEntryStatusDAO.findUnreadBySubscriptions(
subscriptions, null, 0, 1, order, true);
}
}