mirror of
https://github.com/Athou/commafeed.git
synced 2026-11-03 19:05:03 +00:00
apply timeout to all queries
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
package com.commafeed.backend.dao;
|
package com.commafeed.backend.dao;
|
||||||
|
|
||||||
|
import com.commafeed.CommaFeedConfiguration;
|
||||||
import com.commafeed.backend.model.FeedCategory;
|
import com.commafeed.backend.model.FeedCategory;
|
||||||
import com.commafeed.backend.model.QFeedCategory;
|
import com.commafeed.backend.model.QFeedCategory;
|
||||||
import com.commafeed.backend.model.QUser;
|
import com.commafeed.backend.model.QUser;
|
||||||
@@ -17,8 +18,8 @@ public class FeedCategoryDAO extends GenericDAO<FeedCategory> {
|
|||||||
|
|
||||||
private static final QFeedCategory CATEGORY = QFeedCategory.feedCategory;
|
private static final QFeedCategory CATEGORY = QFeedCategory.feedCategory;
|
||||||
|
|
||||||
public FeedCategoryDAO(EntityManager entityManager) {
|
public FeedCategoryDAO(EntityManager entityManager, CommaFeedConfiguration config) {
|
||||||
super(entityManager, FeedCategory.class);
|
super(entityManager, FeedCategory.class, config);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<FeedCategory> findAll(User user) {
|
public List<FeedCategory> findAll(User user) {
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package com.commafeed.backend.dao;
|
package com.commafeed.backend.dao;
|
||||||
|
|
||||||
|
import com.commafeed.CommaFeedConfiguration;
|
||||||
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;
|
||||||
@@ -20,8 +21,8 @@ public class FeedDAO extends GenericDAO<Feed> {
|
|||||||
private static final QFeed FEED = QFeed.feed;
|
private static final QFeed FEED = QFeed.feed;
|
||||||
private static final QFeedSubscription SUBSCRIPTION = QFeedSubscription.feedSubscription;
|
private static final QFeedSubscription SUBSCRIPTION = QFeedSubscription.feedSubscription;
|
||||||
|
|
||||||
public FeedDAO(EntityManager entityManager) {
|
public FeedDAO(EntityManager entityManager, CommaFeedConfiguration config) {
|
||||||
super(entityManager, Feed.class);
|
super(entityManager, Feed.class, config);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Feed> findByIds(List<Long> id) {
|
public List<Feed> findByIds(List<Long> id) {
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package com.commafeed.backend.dao;
|
package com.commafeed.backend.dao;
|
||||||
|
|
||||||
|
import com.commafeed.CommaFeedConfiguration;
|
||||||
import com.commafeed.backend.model.FeedEntryContent;
|
import com.commafeed.backend.model.FeedEntryContent;
|
||||||
import com.commafeed.backend.model.QFeedEntry;
|
import com.commafeed.backend.model.QFeedEntry;
|
||||||
import com.commafeed.backend.model.QFeedEntryContent;
|
import com.commafeed.backend.model.QFeedEntryContent;
|
||||||
@@ -15,8 +16,8 @@ public class FeedEntryContentDAO extends GenericDAO<FeedEntryContent> {
|
|||||||
private static final QFeedEntryContent CONTENT = QFeedEntryContent.feedEntryContent;
|
private static final QFeedEntryContent CONTENT = QFeedEntryContent.feedEntryContent;
|
||||||
private static final QFeedEntry ENTRY = QFeedEntry.feedEntry;
|
private static final QFeedEntry ENTRY = QFeedEntry.feedEntry;
|
||||||
|
|
||||||
public FeedEntryContentDAO(EntityManager entityManager) {
|
public FeedEntryContentDAO(EntityManager entityManager, CommaFeedConfiguration config) {
|
||||||
super(entityManager, FeedEntryContent.class);
|
super(entityManager, FeedEntryContent.class, config);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<FeedEntryContent> findExisting(String contentHash, String titleHash) {
|
public List<FeedEntryContent> findExisting(String contentHash, String titleHash) {
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package com.commafeed.backend.dao;
|
package com.commafeed.backend.dao;
|
||||||
|
|
||||||
|
import com.commafeed.CommaFeedConfiguration;
|
||||||
import com.commafeed.backend.model.Feed;
|
import com.commafeed.backend.model.Feed;
|
||||||
import com.commafeed.backend.model.FeedEntry;
|
import com.commafeed.backend.model.FeedEntry;
|
||||||
import com.commafeed.backend.model.QFeedEntry;
|
import com.commafeed.backend.model.QFeedEntry;
|
||||||
@@ -23,8 +24,8 @@ public class FeedEntryDAO extends GenericDAO<FeedEntry> {
|
|||||||
private static final QFeedEntry ENTRY = QFeedEntry.feedEntry;
|
private static final QFeedEntry ENTRY = QFeedEntry.feedEntry;
|
||||||
private static final int IN_CLAUSE_BATCH_SIZE = 1000;
|
private static final int IN_CLAUSE_BATCH_SIZE = 1000;
|
||||||
|
|
||||||
public FeedEntryDAO(EntityManager entityManager) {
|
public FeedEntryDAO(EntityManager entityManager, CommaFeedConfiguration config) {
|
||||||
super(entityManager, FeedEntry.class);
|
super(entityManager, FeedEntry.class, config);
|
||||||
}
|
}
|
||||||
|
|
||||||
public FeedEntry findExisting(String guidHash, Feed feed) {
|
public FeedEntry findExisting(String guidHash, Feed feed) {
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ public class FeedEntryStatusDAO extends GenericDAO<FeedEntryStatus> {
|
|||||||
EntityManager entityManager,
|
EntityManager entityManager,
|
||||||
FeedEntryTagDAO feedEntryTagDAO,
|
FeedEntryTagDAO feedEntryTagDAO,
|
||||||
CommaFeedConfiguration config) {
|
CommaFeedConfiguration config) {
|
||||||
super(entityManager, FeedEntryStatus.class);
|
super(entityManager, FeedEntryStatus.class, config);
|
||||||
this.feedEntryTagDAO = feedEntryTagDAO;
|
this.feedEntryTagDAO = feedEntryTagDAO;
|
||||||
this.config = config;
|
this.config = config;
|
||||||
}
|
}
|
||||||
@@ -130,8 +130,6 @@ public class FeedEntryStatusDAO extends GenericDAO<FeedEntryStatus> {
|
|||||||
query.limit(limit);
|
query.limit(limit);
|
||||||
}
|
}
|
||||||
|
|
||||||
setTimeout(query, config.database().queryTimeout());
|
|
||||||
|
|
||||||
List<FeedEntryStatus> statuses = query.fetch();
|
List<FeedEntryStatus> statuses = query.fetch();
|
||||||
statuses.forEach(s -> s.setMarkable(true));
|
statuses.forEach(s -> s.setMarkable(true));
|
||||||
if (includeContent) {
|
if (includeContent) {
|
||||||
@@ -208,8 +206,6 @@ public class FeedEntryStatusDAO extends GenericDAO<FeedEntryStatus> {
|
|||||||
query.limit(limit);
|
query.limit(limit);
|
||||||
}
|
}
|
||||||
|
|
||||||
setTimeout(query, config.database().queryTimeout());
|
|
||||||
|
|
||||||
List<FeedEntryStatus> statuses = new ArrayList<>();
|
List<FeedEntryStatus> statuses = new ArrayList<>();
|
||||||
List<Tuple> tuples = query.fetch();
|
List<Tuple> tuples = query.fetch();
|
||||||
for (Tuple tuple : tuples) {
|
for (Tuple tuple : tuples) {
|
||||||
@@ -256,8 +252,6 @@ public class FeedEntryStatusDAO extends GenericDAO<FeedEntryStatus> {
|
|||||||
.where(buildUnreadPredicate())
|
.where(buildUnreadPredicate())
|
||||||
.groupBy(ENTRY.feed.id);
|
.groupBy(ENTRY.feed.id);
|
||||||
|
|
||||||
setTimeout(query, config.database().queryTimeout());
|
|
||||||
|
|
||||||
Map<Long, UnreadCount> result = new HashMap<>();
|
Map<Long, UnreadCount> result = new HashMap<>();
|
||||||
for (Tuple tuple : query.fetch()) {
|
for (Tuple tuple : query.fetch()) {
|
||||||
Long feedId = tuple.get(ENTRY.feed.id);
|
Long feedId = tuple.get(ENTRY.feed.id);
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package com.commafeed.backend.dao;
|
package com.commafeed.backend.dao;
|
||||||
|
|
||||||
|
import com.commafeed.CommaFeedConfiguration;
|
||||||
import com.commafeed.backend.model.FeedEntry;
|
import com.commafeed.backend.model.FeedEntry;
|
||||||
import com.commafeed.backend.model.FeedEntryTag;
|
import com.commafeed.backend.model.FeedEntryTag;
|
||||||
import com.commafeed.backend.model.QFeedEntryTag;
|
import com.commafeed.backend.model.QFeedEntryTag;
|
||||||
@@ -17,8 +18,8 @@ public class FeedEntryTagDAO extends GenericDAO<FeedEntryTag> {
|
|||||||
|
|
||||||
private static final QFeedEntryTag TAG = QFeedEntryTag.feedEntryTag;
|
private static final QFeedEntryTag TAG = QFeedEntryTag.feedEntryTag;
|
||||||
|
|
||||||
public FeedEntryTagDAO(EntityManager entityManager) {
|
public FeedEntryTagDAO(EntityManager entityManager, CommaFeedConfiguration config) {
|
||||||
super(entityManager, FeedEntryTag.class);
|
super(entityManager, FeedEntryTag.class, config);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<String> findByUser(User user) {
|
public List<String> findByUser(User user) {
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package com.commafeed.backend.dao;
|
package com.commafeed.backend.dao;
|
||||||
|
|
||||||
|
import com.commafeed.CommaFeedConfiguration;
|
||||||
import com.commafeed.backend.model.AbstractModel;
|
import com.commafeed.backend.model.AbstractModel;
|
||||||
import com.commafeed.backend.model.Feed;
|
import com.commafeed.backend.model.Feed;
|
||||||
import com.commafeed.backend.model.FeedCategory;
|
import com.commafeed.backend.model.FeedCategory;
|
||||||
@@ -31,8 +32,8 @@ public class FeedSubscriptionDAO extends GenericDAO<FeedSubscription> {
|
|||||||
|
|
||||||
private final EntityManager entityManager;
|
private final EntityManager entityManager;
|
||||||
|
|
||||||
public FeedSubscriptionDAO(EntityManager entityManager) {
|
public FeedSubscriptionDAO(EntityManager entityManager, CommaFeedConfiguration config) {
|
||||||
super(entityManager, FeedSubscription.class);
|
super(entityManager, FeedSubscription.class, config);
|
||||||
this.entityManager = entityManager;
|
this.entityManager = entityManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package com.commafeed.backend.dao;
|
package com.commafeed.backend.dao;
|
||||||
|
|
||||||
|
import com.commafeed.CommaFeedConfiguration;
|
||||||
import com.commafeed.backend.model.AbstractModel;
|
import com.commafeed.backend.model.AbstractModel;
|
||||||
import com.querydsl.core.types.EntityPath;
|
import com.querydsl.core.types.EntityPath;
|
||||||
import com.querydsl.jpa.impl.JPADeleteClause;
|
import com.querydsl.jpa.impl.JPADeleteClause;
|
||||||
@@ -21,9 +22,15 @@ public abstract class GenericDAO<T extends AbstractModel> {
|
|||||||
|
|
||||||
private final EntityManager entityManager;
|
private final EntityManager entityManager;
|
||||||
private final Class<T> entityClass;
|
private final Class<T> entityClass;
|
||||||
|
private final CommaFeedConfiguration config;
|
||||||
|
|
||||||
protected JPAQueryFactory query() {
|
protected JPAQueryFactory query() {
|
||||||
return new JPAQueryFactory(entityManager);
|
return new JPAQueryFactory(entityManager) {
|
||||||
|
@Override
|
||||||
|
public JPAQuery<?> query() {
|
||||||
|
return withTimeout(super.query(), config.database().queryTimeout());
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
protected JPAUpdateClause updateQuery(EntityPath<T> entityPath) {
|
protected JPAUpdateClause updateQuery(EntityPath<T> entityPath) {
|
||||||
@@ -57,9 +64,10 @@ public abstract class GenericDAO<T extends AbstractModel> {
|
|||||||
return objects.size();
|
return objects.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void setTimeout(JPAQuery<?> query, Duration timeout) {
|
private JPAQuery<?> withTimeout(JPAQuery<?> query, Duration timeout) {
|
||||||
if (!timeout.isZero()) {
|
if (!timeout.isZero()) {
|
||||||
query.setHint(SpecHints.HINT_SPEC_QUERY_TIMEOUT, Math.toIntExact(timeout.toMillis()));
|
query.setHint(SpecHints.HINT_SPEC_QUERY_TIMEOUT, Math.toIntExact(timeout.toMillis()));
|
||||||
}
|
}
|
||||||
|
return query;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package com.commafeed.backend.dao;
|
package com.commafeed.backend.dao;
|
||||||
|
|
||||||
|
import com.commafeed.CommaFeedConfiguration;
|
||||||
import com.commafeed.backend.model.QUser;
|
import com.commafeed.backend.model.QUser;
|
||||||
import com.commafeed.backend.model.User;
|
import com.commafeed.backend.model.User;
|
||||||
|
|
||||||
@@ -11,8 +12,8 @@ public class UserDAO extends GenericDAO<User> {
|
|||||||
|
|
||||||
private static final QUser USER = QUser.user;
|
private static final QUser USER = QUser.user;
|
||||||
|
|
||||||
public UserDAO(EntityManager entityManager) {
|
public UserDAO(EntityManager entityManager, CommaFeedConfiguration config) {
|
||||||
super(entityManager, User.class);
|
super(entityManager, User.class, config);
|
||||||
}
|
}
|
||||||
|
|
||||||
public User findByName(String name) {
|
public User findByName(String name) {
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package com.commafeed.backend.dao;
|
package com.commafeed.backend.dao;
|
||||||
|
|
||||||
|
import com.commafeed.CommaFeedConfiguration;
|
||||||
import com.commafeed.backend.model.QUserRole;
|
import com.commafeed.backend.model.QUserRole;
|
||||||
import com.commafeed.backend.model.User;
|
import com.commafeed.backend.model.User;
|
||||||
import com.commafeed.backend.model.UserRole;
|
import com.commafeed.backend.model.UserRole;
|
||||||
@@ -17,8 +18,8 @@ public class UserRoleDAO extends GenericDAO<UserRole> {
|
|||||||
|
|
||||||
private static final QUserRole ROLE = QUserRole.userRole;
|
private static final QUserRole ROLE = QUserRole.userRole;
|
||||||
|
|
||||||
public UserRoleDAO(EntityManager entityManager) {
|
public UserRoleDAO(EntityManager entityManager, CommaFeedConfiguration config) {
|
||||||
super(entityManager, UserRole.class);
|
super(entityManager, UserRole.class, config);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<UserRole> findAll() {
|
public List<UserRole> findAll() {
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package com.commafeed.backend.dao;
|
package com.commafeed.backend.dao;
|
||||||
|
|
||||||
|
import com.commafeed.CommaFeedConfiguration;
|
||||||
import com.commafeed.backend.model.QUserSettings;
|
import com.commafeed.backend.model.QUserSettings;
|
||||||
import com.commafeed.backend.model.User;
|
import com.commafeed.backend.model.User;
|
||||||
import com.commafeed.backend.model.UserSettings;
|
import com.commafeed.backend.model.UserSettings;
|
||||||
@@ -12,8 +13,8 @@ public class UserSettingsDAO extends GenericDAO<UserSettings> {
|
|||||||
|
|
||||||
private static final QUserSettings SETTINGS = QUserSettings.userSettings;
|
private static final QUserSettings SETTINGS = QUserSettings.userSettings;
|
||||||
|
|
||||||
public UserSettingsDAO(EntityManager entityManager) {
|
public UserSettingsDAO(EntityManager entityManager, CommaFeedConfiguration config) {
|
||||||
super(entityManager, UserSettings.class);
|
super(entityManager, UserSettings.class, config);
|
||||||
}
|
}
|
||||||
|
|
||||||
public UserSettings findByUser(User user) {
|
public UserSettings findByUser(User user) {
|
||||||
|
|||||||
Reference in New Issue
Block a user