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.Feed;
|
||||||
import com.commafeed.backend.model.QFeed;
|
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.google.common.collect.Iterables;
|
import com.google.common.collect.Iterables;
|
||||||
import com.querydsl.jpa.JPAExpressions;
|
import com.querydsl.jpa.JPAExpressions;
|
||||||
import com.querydsl.jpa.JPQLQuery;
|
|
||||||
|
|
||||||
@Singleton
|
@Singleton
|
||||||
public class FeedDAO extends GenericDAO<Feed> {
|
public class FeedDAO extends GenericDAO<Feed> {
|
||||||
@@ -28,18 +26,12 @@ public class FeedDAO extends GenericDAO<Feed> {
|
|||||||
super(sessionFactory);
|
super(sessionFactory);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Feed> findNextUpdatable(int count, Date lastLoginThreshold) {
|
public List<Feed> findNextUpdatable(int count) {
|
||||||
JPQLQuery<Feed> query = query().selectFrom(feed);
|
return query().selectFrom(feed)
|
||||||
query.where(feed.disabledUntil.isNull().or(feed.disabledUntil.lt(new Date())));
|
.where(feed.disabledUntil.isNull().or(feed.disabledUntil.lt(new Date())))
|
||||||
|
.orderBy(feed.disabledUntil.asc())
|
||||||
if (lastLoginThreshold != null) {
|
.limit(count)
|
||||||
QFeedSubscription subs = QFeedSubscription.feedSubscription;
|
.fetch();
|
||||||
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 void setDisabledUntil(List<Long> feedIds, Date date) {
|
public void setDisabledUntil(List<Long> feedIds, Date date) {
|
||||||
|
|||||||
@@ -162,7 +162,7 @@ public class FeedRefreshEngine implements Managed {
|
|||||||
|
|
||||||
private List<Feed> getNextUpdatableFeeds(int max) {
|
private List<Feed> getNextUpdatableFeeds(int max) {
|
||||||
return UnitOfWork.call(sessionFactory, () -> {
|
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()
|
// update disabledUntil to prevent feeds from being returned again by feedDAO.findNextUpdatable()
|
||||||
Date nextUpdateDate = DateUtils.addMinutes(new Date(), config.getApplicationSettings().getRefreshIntervalMinutes());
|
Date nextUpdateDate = DateUtils.addMinutes(new Date(), config.getApplicationSettings().getRefreshIntervalMinutes());
|
||||||
feedDAO.setDisabledUntil(feeds.stream().map(AbstractModel::getId).collect(Collectors.toList()), nextUpdateDate);
|
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());
|
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
|
@Override
|
||||||
public void stop() {
|
public void stop() {
|
||||||
this.feedProcessingLoopExecutor.shutdownNow();
|
this.feedProcessingLoopExecutor.shutdownNow();
|
||||||
|
|||||||
Reference in New Issue
Block a user