mirror of
https://github.com/Athou/commafeed.git
synced 2026-03-21 21:37:29 +00:00
rewrote query (#53)
This commit is contained in:
@@ -6,12 +6,14 @@ import javax.ejb.Stateless;
|
||||
import javax.persistence.TypedQuery;
|
||||
import javax.persistence.criteria.CriteriaQuery;
|
||||
import javax.persistence.criteria.Root;
|
||||
import javax.persistence.criteria.SetJoin;
|
||||
|
||||
import org.apache.commons.codec.digest.DigestUtils;
|
||||
|
||||
import com.commafeed.backend.model.Feed;
|
||||
import com.commafeed.backend.model.FeedEntry;
|
||||
import com.commafeed.backend.model.FeedEntry_;
|
||||
import com.commafeed.backend.model.Feed_;
|
||||
import com.google.api.client.util.Lists;
|
||||
import com.uaihebert.model.EasyCriteria;
|
||||
|
||||
@@ -41,11 +43,11 @@ public class FeedEntryDAO extends GenericDAO<FeedEntry> {
|
||||
public List<FeedEntry> findByFeed(Feed feed, int offset, int limit) {
|
||||
CriteriaQuery<FeedEntry> query = builder.createQuery(getType());
|
||||
Root<FeedEntry> root = query.from(getType());
|
||||
query.where(builder.isMember(feed, root.get(FeedEntry_.feeds)));
|
||||
SetJoin<FeedEntry, Feed> feedsJoin = root.join(FeedEntry_.feeds);
|
||||
query.where(builder.equal(feedsJoin.get(Feed_.id), feed.getId()));
|
||||
query.orderBy(builder.desc(root.get(FeedEntry_.updated)));
|
||||
TypedQuery<FeedEntry> q = em.createQuery(query);
|
||||
q.setFirstResult(offset);
|
||||
q.setMaxResults(limit);
|
||||
limit(q, offset, limit);
|
||||
return q.getResultList();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -129,7 +129,7 @@ public abstract class GenericDAO<T extends AbstractModel> {
|
||||
return criteria.getResultList();
|
||||
}
|
||||
|
||||
protected void limit(TypedQuery<FeedEntryStatus> query, int offset,
|
||||
protected void limit(TypedQuery<?> query, int offset,
|
||||
int limit) {
|
||||
if (offset > -1) {
|
||||
query.setFirstResult(offset);
|
||||
|
||||
@@ -48,9 +48,6 @@ public class FeedSubscriptionService {
|
||||
sub.setTitle(title.substring(0, Math.min(128, title.length())));
|
||||
feedSubscriptionDAO.saveOrUpdate(sub);
|
||||
|
||||
// TODO optimize this request, it takes ages to complete, skipping for
|
||||
// now
|
||||
newSubscription = false;
|
||||
if (newSubscription) {
|
||||
List<FeedEntryStatus> statuses = Lists.newArrayList();
|
||||
List<FeedEntry> allEntries = feedEntryDAO.findByFeed(feed, 0, 10);
|
||||
|
||||
Reference in New Issue
Block a user