forked from Archives/Athou_commafeed
remove very slow query
This commit is contained in:
@@ -13,10 +13,8 @@ import org.hibernate.SessionFactory;
|
||||
import com.commafeed.backend.model.Feed;
|
||||
import com.commafeed.backend.model.QFeed;
|
||||
import com.commafeed.backend.model.QFeedSubscription;
|
||||
import com.commafeed.backend.model.QUser;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.querydsl.jpa.JPAExpressions;
|
||||
import com.querydsl.jpa.JPQLQuery;
|
||||
|
||||
@Singleton
|
||||
public class FeedDAO extends GenericDAO<Feed> {
|
||||
@@ -28,18 +26,12 @@ public class FeedDAO extends GenericDAO<Feed> {
|
||||
super(sessionFactory);
|
||||
}
|
||||
|
||||
public List<Feed> findNextUpdatable(int count, Date lastLoginThreshold) {
|
||||
JPQLQuery<Feed> query = query().selectFrom(feed);
|
||||
query.where(feed.disabledUntil.isNull().or(feed.disabledUntil.lt(new Date())));
|
||||
|
||||
if (lastLoginThreshold != null) {
|
||||
QFeedSubscription subs = QFeedSubscription.feedSubscription;
|
||||
QUser user = QUser.user;
|
||||
|
||||
query.join(subs).on(subs.feed.id.eq(feed.id)).join(subs.user, user).where(user.lastLogin.gt(lastLoginThreshold));
|
||||
}
|
||||
|
||||
return query.orderBy(feed.disabledUntil.asc()).limit(count).fetch();
|
||||
public List<Feed> findNextUpdatable(int count) {
|
||||
return query().selectFrom(feed)
|
||||
.where(feed.disabledUntil.isNull().or(feed.disabledUntil.lt(new Date())))
|
||||
.orderBy(feed.disabledUntil.asc())
|
||||
.limit(count)
|
||||
.fetch();
|
||||
}
|
||||
|
||||
public void setDisabledUntil(List<Long> feedIds, Date date) {
|
||||
|
||||
@@ -162,7 +162,7 @@ public class FeedRefreshEngine implements Managed {
|
||||
|
||||
private List<Feed> getNextUpdatableFeeds(int max) {
|
||||
return UnitOfWork.call(sessionFactory, () -> {
|
||||
List<Feed> feeds = feedDAO.findNextUpdatable(max, getLastLoginThreshold());
|
||||
List<Feed> feeds = feedDAO.findNextUpdatable(max);
|
||||
// update disabledUntil to prevent feeds from being returned again by feedDAO.findNextUpdatable()
|
||||
Date nextUpdateDate = DateUtils.addMinutes(new Date(), config.getApplicationSettings().getRefreshIntervalMinutes());
|
||||
feedDAO.setDisabledUntil(feeds.stream().map(AbstractModel::getId).collect(Collectors.toList()), nextUpdateDate);
|
||||
@@ -174,10 +174,6 @@ public class FeedRefreshEngine implements Managed {
|
||||
return Math.min(100, 3 * config.getApplicationSettings().getBackgroundThreads());
|
||||
}
|
||||
|
||||
private Date getLastLoginThreshold() {
|
||||
return Boolean.TRUE.equals(config.getApplicationSettings().getHeavyLoad()) ? DateUtils.addDays(new Date(), -30) : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stop() {
|
||||
this.feedProcessingLoopExecutor.shutdownNow();
|
||||
|
||||
Reference in New Issue
Block a user