mirror of
https://github.com/Athou/commafeed.git
synced 2026-03-21 21:37:29 +00:00
rewrite query using subqueries
This commit is contained in:
@@ -15,7 +15,6 @@ import com.commafeed.backend.model.QFeed;
|
|||||||
import com.commafeed.backend.model.QFeedSubscription;
|
import com.commafeed.backend.model.QFeedSubscription;
|
||||||
import com.commafeed.backend.model.QUser;
|
import com.commafeed.backend.model.QUser;
|
||||||
import com.google.common.collect.Iterables;
|
import com.google.common.collect.Iterables;
|
||||||
import com.mysema.query.BooleanBuilder;
|
|
||||||
import com.mysema.query.jpa.hibernate.HibernateQuery;
|
import com.mysema.query.jpa.hibernate.HibernateQuery;
|
||||||
import com.mysema.query.jpa.hibernate.HibernateSubQuery;
|
import com.mysema.query.jpa.hibernate.HibernateSubQuery;
|
||||||
|
|
||||||
@@ -30,19 +29,16 @@ public class FeedDAO extends GenericDAO<Feed> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public List<Feed> findNextUpdatable(int count, Date lastLoginThreshold) {
|
public List<Feed> findNextUpdatable(int count, Date lastLoginThreshold) {
|
||||||
BooleanBuilder disabledDatePredicate = new BooleanBuilder();
|
HibernateQuery query = newQuery().from(feed);
|
||||||
disabledDatePredicate.or(feed.disabledUntil.isNull());
|
query.where(feed.disabledUntil.isNull().or(feed.disabledUntil.lt(new Date())));
|
||||||
disabledDatePredicate.or(feed.disabledUntil.lt(new Date()));
|
|
||||||
|
|
||||||
HibernateQuery query = null;
|
|
||||||
if (lastLoginThreshold != null) {
|
if (lastLoginThreshold != null) {
|
||||||
QFeedSubscription subs = QFeedSubscription.feedSubscription;
|
QFeedSubscription subs = QFeedSubscription.feedSubscription;
|
||||||
QUser user = QUser.user;
|
QUser user = QUser.user;
|
||||||
query = newQuery().from(subs);
|
|
||||||
query.join(subs.feed, feed).join(subs.user, user).where(disabledDatePredicate, user.lastLogin.gt(lastLoginThreshold));
|
HibernateSubQuery subQuery = new HibernateSubQuery().from(subs);
|
||||||
} else {
|
subQuery.join(subs.user, user).where(user.lastLogin.gt(lastLoginThreshold));
|
||||||
query = newQuery().from(feed);
|
query.where(subQuery.exists());
|
||||||
query.where(disabledDatePredicate);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return query.orderBy(feed.disabledUntil.asc()).limit(count).distinct().list(feed);
|
return query.orderBy(feed.disabledUntil.asc()).limit(count).distinct().list(feed);
|
||||||
|
|||||||
Reference in New Issue
Block a user