query optimizations

This commit is contained in:
Jeremie Panzer
2013-03-27 10:46:30 +01:00
parent 4882c39aca
commit f5a32fce13
4 changed files with 8 additions and 12 deletions

View File

@@ -6,7 +6,6 @@ import javax.ejb.Stateless;
import javax.inject.Inject;
import com.commafeed.backend.model.Feed;
import com.commafeed.backend.model.FeedCategory;
import com.commafeed.backend.model.FeedSubscription;
import com.commafeed.backend.model.User;
import com.commafeed.frontend.utils.ModelFactory.MF;
@@ -36,14 +35,14 @@ public class FeedSubscriptionService extends GenericDAO<FeedSubscription, Long>
}
public List<FeedSubscription> findAll(User user) {
return findByField(MF.i(MF.p(FeedCategory.class).getUser()), user);
return findByField(MF.i(proxy().getUser()), user);
}
public List<FeedSubscription> findWithoutCategories(User user) {
EasyCriteria<FeedSubscription> criteria = EasyCriteriaFactory
.createQueryCriteria(em, getType());
criteria.andEquals("user", user);
criteria.andIsNull("category");
criteria.andEquals(MF.i(proxy().getUser()), user);
criteria.andIsNull(MF.i(proxy().getCategory()));
return criteria.getResultList();
}

View File

@@ -5,7 +5,6 @@ import java.util.Set;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Lob;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
@@ -23,7 +22,7 @@ public class FeedEntry extends AbstractModel {
@Column(length = 2048)
private String guid;
@ManyToOne(fetch = FetchType.EAGER)
@ManyToOne
private Feed feed;
@Column(length = 2048)

View File

@@ -2,7 +2,6 @@ package com.commafeed.backend.model;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
@@ -11,10 +10,10 @@ import javax.persistence.Table;
@SuppressWarnings("serial")
public class FeedSubscription extends AbstractModel {
@ManyToOne(fetch = FetchType.EAGER)
@ManyToOne
private User user;
@ManyToOne(fetch = FetchType.EAGER)
@ManyToOne
private Feed feed;
@Column(length = 128)

View File

@@ -61,8 +61,7 @@ public class EntriesREST extends AbstractREST {
} else {
FeedCategory feedCategory = null;
if (!ALL.equals(id)) {
feedCategory = new FeedCategory();
feedCategory.setId(Long.valueOf(id));
feedCategory = feedCategoryService.findById(getUser(), Long.valueOf(id));
}
List<FeedCategory> childrenCategories = feedCategoryService
.findAllChildrenCategories(getUser(), feedCategory);
@@ -75,7 +74,7 @@ public class EntriesREST extends AbstractREST {
}
});
entries.setName(ALL.equals(id) ? ALL : feedCategory.getName());
entries.setName(ALL.equals(id) ? "All" : feedCategory.getName());
entries.getEntries().addAll(
buildEntries(childrenCategories, subMapping, offset, limit,
unreadOnly));