mirror of
https://github.com/Athou/commafeed.git
synced 2026-03-21 21:37:29 +00:00
persist read status instead of unread status
This commit is contained in:
@@ -10,33 +10,38 @@ import javax.inject.Inject;
|
|||||||
import javax.persistence.Query;
|
import javax.persistence.Query;
|
||||||
import javax.persistence.TypedQuery;
|
import javax.persistence.TypedQuery;
|
||||||
import javax.persistence.criteria.CriteriaQuery;
|
import javax.persistence.criteria.CriteriaQuery;
|
||||||
import javax.persistence.criteria.Join;
|
|
||||||
import javax.persistence.criteria.Path;
|
import javax.persistence.criteria.Path;
|
||||||
import javax.persistence.criteria.Predicate;
|
import javax.persistence.criteria.Predicate;
|
||||||
import javax.persistence.criteria.Root;
|
import javax.persistence.criteria.Root;
|
||||||
|
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
import org.apache.commons.lang3.ObjectUtils;
|
import org.apache.commons.lang3.ObjectUtils;
|
||||||
|
import org.hibernate.Criteria;
|
||||||
|
import org.hibernate.criterion.Disjunction;
|
||||||
|
import org.hibernate.criterion.Order;
|
||||||
|
import org.hibernate.criterion.ProjectionList;
|
||||||
|
import org.hibernate.criterion.Projections;
|
||||||
|
import org.hibernate.criterion.Restrictions;
|
||||||
|
import org.hibernate.sql.JoinType;
|
||||||
|
import org.hibernate.transform.Transformers;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import com.commafeed.backend.FixedSizeSortedSet;
|
import com.commafeed.backend.FixedSizeSortedSet;
|
||||||
import com.commafeed.backend.model.FeedEntry;
|
import com.commafeed.backend.model.FeedEntry;
|
||||||
import com.commafeed.backend.model.FeedEntryContent;
|
|
||||||
import com.commafeed.backend.model.FeedEntryContent_;
|
import com.commafeed.backend.model.FeedEntryContent_;
|
||||||
import com.commafeed.backend.model.FeedEntryStatus;
|
import com.commafeed.backend.model.FeedEntryStatus;
|
||||||
import com.commafeed.backend.model.FeedEntryStatus_;
|
import com.commafeed.backend.model.FeedEntryStatus_;
|
||||||
import com.commafeed.backend.model.FeedEntry_;
|
import com.commafeed.backend.model.FeedEntry_;
|
||||||
import com.commafeed.backend.model.FeedFeedEntry;
|
|
||||||
import com.commafeed.backend.model.FeedFeedEntry_;
|
import com.commafeed.backend.model.FeedFeedEntry_;
|
||||||
import com.commafeed.backend.model.FeedSubscription;
|
import com.commafeed.backend.model.FeedSubscription;
|
||||||
import com.commafeed.backend.model.Models;
|
import com.commafeed.backend.model.Models;
|
||||||
import com.commafeed.backend.model.User;
|
import com.commafeed.backend.model.User;
|
||||||
import com.commafeed.backend.model.UserSettings.ReadingOrder;
|
import com.commafeed.backend.model.UserSettings.ReadingOrder;
|
||||||
import com.commafeed.backend.services.ApplicationSettingsService;
|
import com.commafeed.backend.services.ApplicationSettingsService;
|
||||||
|
import com.google.api.client.util.Maps;
|
||||||
import com.google.common.collect.Iterables;
|
import com.google.common.collect.Iterables;
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import com.google.common.collect.Maps;
|
|
||||||
|
|
||||||
@Stateless
|
@Stateless
|
||||||
public class FeedEntryStatusDAO extends GenericDAO<FeedEntryStatus> {
|
public class FeedEntryStatusDAO extends GenericDAO<FeedEntryStatus> {
|
||||||
@@ -58,20 +63,6 @@ public class FeedEntryStatusDAO extends GenericDAO<FeedEntryStatus> {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
private static final Comparator<FeedEntryStatus> STATUS_COMPARATOR_DESC = new Comparator<FeedEntryStatus>() {
|
|
||||||
@Override
|
|
||||||
public int compare(FeedEntryStatus o1, FeedEntryStatus o2) {
|
|
||||||
return ObjectUtils.compare(o2.getEntryUpdated(), o1.getEntryUpdated());
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
private static final Comparator<FeedEntryStatus> STATUS_COMPARATOR_ASC = new Comparator<FeedEntryStatus>() {
|
|
||||||
@Override
|
|
||||||
public int compare(FeedEntryStatus o1, FeedEntryStatus o2) {
|
|
||||||
return ObjectUtils.compare(o1.getEntryUpdated(), o2.getEntryUpdated());
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
ApplicationSettingsService applicationSettingsService;
|
ApplicationSettingsService applicationSettingsService;
|
||||||
|
|
||||||
@@ -90,7 +81,7 @@ public class FeedEntryStatusDAO extends GenericDAO<FeedEntryStatus> {
|
|||||||
FeedEntryStatus status = Iterables.getFirst(statuses, null);
|
FeedEntryStatus status = Iterables.getFirst(statuses, null);
|
||||||
if (status == null) {
|
if (status == null) {
|
||||||
status = new FeedEntryStatus(sub.getUser(), sub, entry);
|
status = new FeedEntryStatus(sub.getUser(), sub, entry);
|
||||||
status.setRead(true);
|
status.setRead(false);
|
||||||
}
|
}
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
@@ -120,10 +111,94 @@ public class FeedEntryStatusDAO extends GenericDAO<FeedEntryStatus> {
|
|||||||
return lazyLoadContent(includeContent, q.getResultList());
|
return lazyLoadContent(includeContent, q.getResultList());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Criteria buildSearchCriteria(FeedSubscription sub,
|
||||||
|
boolean unreadOnly, String keywords, Date newerThan, int offset,
|
||||||
|
int limit, ReadingOrder order, boolean includeContent,
|
||||||
|
FeedEntry last) {
|
||||||
|
Criteria criteria = getSession().createCriteria(FeedEntry.class,
|
||||||
|
"entry");
|
||||||
|
|
||||||
|
Criteria ffeJoin = criteria.createCriteria(
|
||||||
|
FeedEntry_.feedRelationships.getName(), "ffe",
|
||||||
|
JoinType.INNER_JOIN);
|
||||||
|
ffeJoin.add(Restrictions.eq(FeedFeedEntry_.feed.getName(),
|
||||||
|
sub.getFeed()));
|
||||||
|
|
||||||
|
if (newerThan != null) {
|
||||||
|
criteria.add(Restrictions.ge(FeedEntry_.inserted.getName(),
|
||||||
|
newerThan));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (keywords != null) {
|
||||||
|
Criteria contentJoin = criteria.createCriteria(
|
||||||
|
FeedEntry_.content.getName(), "content",
|
||||||
|
JoinType.INNER_JOIN);
|
||||||
|
|
||||||
|
String joinedKeywords = StringUtils.join(keywords.toLowerCase()
|
||||||
|
.split(" "), "%");
|
||||||
|
joinedKeywords = "%" + joinedKeywords + "%";
|
||||||
|
|
||||||
|
Disjunction or = Restrictions.disjunction();
|
||||||
|
or.add(Restrictions.ilike(FeedEntryContent_.content.getName(),
|
||||||
|
joinedKeywords));
|
||||||
|
or.add(Restrictions.ilike(FeedEntryContent_.title.getName(),
|
||||||
|
joinedKeywords));
|
||||||
|
contentJoin.add(or);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (unreadOnly) {
|
||||||
|
|
||||||
|
Criteria statusJoin = criteria.createCriteria(FeedEntry_.statuses
|
||||||
|
.getName(), "status", JoinType.LEFT_OUTER_JOIN,
|
||||||
|
Restrictions.eq(FeedEntryStatus_.subscription.getName(),
|
||||||
|
sub));
|
||||||
|
|
||||||
|
Disjunction or = Restrictions.disjunction();
|
||||||
|
or.add(Restrictions.isNull(FeedEntryStatus_.id.getName()));
|
||||||
|
or.add(Restrictions.eq(FeedEntryStatus_.read.getName(), false));
|
||||||
|
|
||||||
|
statusJoin.add(or);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (last != null) {
|
||||||
|
if (order == ReadingOrder.desc) {
|
||||||
|
ffeJoin.add(Restrictions.gt(
|
||||||
|
FeedFeedEntry_.entryUpdated.getName(),
|
||||||
|
last.getUpdated()));
|
||||||
|
} else {
|
||||||
|
ffeJoin.add(Restrictions.lt(
|
||||||
|
FeedFeedEntry_.entryUpdated.getName(),
|
||||||
|
last.getUpdated()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (order != null) {
|
||||||
|
Order o = null;
|
||||||
|
if (order == ReadingOrder.asc) {
|
||||||
|
o = Order.asc(FeedEntry_.updated.getName());
|
||||||
|
} else {
|
||||||
|
o = Order.desc(FeedEntry_.updated.getName());
|
||||||
|
}
|
||||||
|
criteria.addOrder(o);
|
||||||
|
}
|
||||||
|
if (offset > -1) {
|
||||||
|
criteria.setFirstResult(offset);
|
||||||
|
}
|
||||||
|
if (limit > -1) {
|
||||||
|
criteria.setMaxResults(limit);
|
||||||
|
}
|
||||||
|
int timeout = applicationSettingsService.get().getQueryTimeout();
|
||||||
|
if (timeout > 0) {
|
||||||
|
criteria.setTimeout(timeout);
|
||||||
|
}
|
||||||
|
return criteria;
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
public List<FeedEntryStatus> findBySubscriptions(
|
public List<FeedEntryStatus> findBySubscriptions(
|
||||||
List<FeedSubscription> subscriptions, String keywords,
|
List<FeedSubscription> subscriptions, boolean unreadOnly,
|
||||||
Date newerThan, int offset, int limit, ReadingOrder order,
|
String keywords, Date newerThan, int offset, int limit,
|
||||||
boolean includeContent) {
|
ReadingOrder order, boolean includeContent) {
|
||||||
|
|
||||||
int capacity = offset + limit;
|
int capacity = offset + limit;
|
||||||
Comparator<FeedEntry> comparator = order == ReadingOrder.desc ? ENTRY_COMPARATOR_DESC
|
Comparator<FeedEntry> comparator = order == ReadingOrder.desc ? ENTRY_COMPARATOR_DESC
|
||||||
@@ -131,58 +206,12 @@ public class FeedEntryStatusDAO extends GenericDAO<FeedEntryStatus> {
|
|||||||
FixedSizeSortedSet<FeedEntry> set = new FixedSizeSortedSet<FeedEntry>(
|
FixedSizeSortedSet<FeedEntry> set = new FixedSizeSortedSet<FeedEntry>(
|
||||||
capacity < 0 ? Integer.MAX_VALUE : capacity, comparator);
|
capacity < 0 ? Integer.MAX_VALUE : capacity, comparator);
|
||||||
for (FeedSubscription sub : subscriptions) {
|
for (FeedSubscription sub : subscriptions) {
|
||||||
CriteriaQuery<FeedEntry> query = builder
|
FeedEntry last = (order != null && set.isFull()) ? set.last()
|
||||||
.createQuery(FeedEntry.class);
|
: null;
|
||||||
Root<FeedEntry> root = query.from(FeedEntry.class);
|
Criteria criteria = buildSearchCriteria(sub, unreadOnly, keywords,
|
||||||
Join<FeedEntry, FeedFeedEntry> ffeJoin = root
|
newerThan, -1, limit, order, includeContent, last);
|
||||||
.join(FeedEntry_.feedRelationships);
|
|
||||||
|
|
||||||
List<Predicate> predicates = Lists.newArrayList();
|
List<FeedEntry> list = criteria.list();
|
||||||
predicates.add(builder.equal(ffeJoin.get(FeedFeedEntry_.feed),
|
|
||||||
sub.getFeed()));
|
|
||||||
|
|
||||||
if (newerThan != null) {
|
|
||||||
predicates.add(builder.greaterThanOrEqualTo(
|
|
||||||
root.get(FeedEntry_.inserted), newerThan));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (keywords != null) {
|
|
||||||
Join<FeedEntry, FeedEntryContent> contentJoin = root
|
|
||||||
.join(FeedEntry_.content);
|
|
||||||
|
|
||||||
String joinedKeywords = StringUtils.join(keywords.toLowerCase()
|
|
||||||
.split(" "), "%");
|
|
||||||
joinedKeywords = "%" + joinedKeywords + "%";
|
|
||||||
|
|
||||||
Predicate content = builder.like(builder.lower(contentJoin
|
|
||||||
.get(FeedEntryContent_.content)), joinedKeywords);
|
|
||||||
Predicate title = builder
|
|
||||||
.like(builder.lower(contentJoin
|
|
||||||
.get(FeedEntryContent_.title)), joinedKeywords);
|
|
||||||
predicates.add(builder.or(content, title));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (order != null && !set.isEmpty() && set.isFull()) {
|
|
||||||
Predicate filter = null;
|
|
||||||
FeedEntry last = set.last();
|
|
||||||
if (order == ReadingOrder.desc) {
|
|
||||||
filter = builder.greaterThan(
|
|
||||||
ffeJoin.get(FeedFeedEntry_.entryUpdated),
|
|
||||||
last.getUpdated());
|
|
||||||
} else {
|
|
||||||
filter = builder.lessThan(
|
|
||||||
ffeJoin.get(FeedFeedEntry_.entryUpdated),
|
|
||||||
last.getUpdated());
|
|
||||||
}
|
|
||||||
predicates.add(filter);
|
|
||||||
}
|
|
||||||
query.where(predicates.toArray(new Predicate[0]));
|
|
||||||
orderEntriesBy(query, ffeJoin, order);
|
|
||||||
TypedQuery<FeedEntry> q = em.createQuery(query);
|
|
||||||
limit(q, 0, capacity);
|
|
||||||
setTimeout(q);
|
|
||||||
|
|
||||||
List<FeedEntry> list = q.getResultList();
|
|
||||||
for (FeedEntry entry : list) {
|
for (FeedEntry entry : list) {
|
||||||
entry.setSubscription(sub);
|
entry.setSubscription(sub);
|
||||||
}
|
}
|
||||||
@@ -206,105 +235,29 @@ public class FeedEntryStatusDAO extends GenericDAO<FeedEntryStatus> {
|
|||||||
return lazyLoadContent(includeContent, results);
|
return lazyLoadContent(includeContent, results);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<FeedEntryStatus> findUnreadBySubscriptions(
|
@SuppressWarnings("unchecked")
|
||||||
List<FeedSubscription> subscriptions, Date newerThan, int offset,
|
public Long getUnreadCount(FeedSubscription subscription) {
|
||||||
int limit, ReadingOrder order, boolean includeContent) {
|
Long count = null;
|
||||||
|
Criteria criteria = buildSearchCriteria(subscription, true, null, null,
|
||||||
int capacity = offset + limit;
|
-1, -1, null, false, null);
|
||||||
Comparator<FeedEntryStatus> comparator = order == ReadingOrder.desc ? STATUS_COMPARATOR_DESC
|
ProjectionList projection = Projections.projectionList();
|
||||||
: STATUS_COMPARATOR_ASC;
|
projection.add(Projections.rowCount(), "count");
|
||||||
FixedSizeSortedSet<FeedEntryStatus> set = new FixedSizeSortedSet<FeedEntryStatus>(
|
criteria.setProjection(projection);
|
||||||
capacity < 0 ? Integer.MAX_VALUE : capacity, comparator);
|
criteria.setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP);
|
||||||
for (FeedSubscription sub : subscriptions) {
|
List<Map<String, Long>> list = criteria.list();
|
||||||
CriteriaQuery<FeedEntryStatus> query = builder
|
for (Map<String, Long> row : list) {
|
||||||
.createQuery(getType());
|
count = row.get("count");
|
||||||
Root<FeedEntryStatus> root = query.from(getType());
|
|
||||||
|
|
||||||
List<Predicate> predicates = Lists.newArrayList();
|
|
||||||
|
|
||||||
predicates.add(builder.equal(
|
|
||||||
root.get(FeedEntryStatus_.subscription), sub));
|
|
||||||
predicates.add(builder.isFalse(root.get(FeedEntryStatus_.read)));
|
|
||||||
|
|
||||||
if (newerThan != null) {
|
|
||||||
predicates.add(builder.greaterThanOrEqualTo(
|
|
||||||
root.get(FeedEntryStatus_.entryInserted), newerThan));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (order != null && !set.isEmpty() && set.isFull()) {
|
|
||||||
Predicate filter = null;
|
|
||||||
FeedEntryStatus last = set.last();
|
|
||||||
if (order == ReadingOrder.desc) {
|
|
||||||
filter = builder.greaterThan(
|
|
||||||
root.get(FeedEntryStatus_.entryUpdated),
|
|
||||||
last.getEntryUpdated());
|
|
||||||
} else {
|
|
||||||
filter = builder.lessThan(
|
|
||||||
root.get(FeedEntryStatus_.entryUpdated),
|
|
||||||
last.getEntryUpdated());
|
|
||||||
}
|
|
||||||
predicates.add(filter);
|
|
||||||
}
|
|
||||||
query.where(predicates.toArray(new Predicate[0]));
|
|
||||||
orderStatusesBy(query, root, order);
|
|
||||||
|
|
||||||
TypedQuery<FeedEntryStatus> q = em.createQuery(query);
|
|
||||||
limit(q, -1, limit);
|
|
||||||
setTimeout(q);
|
|
||||||
|
|
||||||
List<FeedEntryStatus> list = q.getResultList();
|
|
||||||
set.addAll(list);
|
|
||||||
}
|
}
|
||||||
|
return count;
|
||||||
List<FeedEntryStatus> entries = set.asList();
|
|
||||||
int size = entries.size();
|
|
||||||
if (size < offset) {
|
|
||||||
return Lists.newArrayList();
|
|
||||||
}
|
|
||||||
|
|
||||||
entries = entries.subList(Math.max(offset, 0), size);
|
|
||||||
return lazyLoadContent(includeContent, entries);
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<FeedEntryStatus> findAllUnread(User user, Date newerThan,
|
|
||||||
int offset, int limit, ReadingOrder order, boolean includeContent) {
|
|
||||||
|
|
||||||
CriteriaQuery<FeedEntryStatus> query = builder.createQuery(getType());
|
|
||||||
Root<FeedEntryStatus> root = query.from(getType());
|
|
||||||
|
|
||||||
List<Predicate> predicates = Lists.newArrayList();
|
|
||||||
|
|
||||||
predicates.add(builder.equal(root.get(FeedEntryStatus_.user), user));
|
|
||||||
predicates.add(builder.isFalse(root.get(FeedEntryStatus_.read)));
|
|
||||||
|
|
||||||
if (newerThan != null) {
|
|
||||||
predicates.add(builder.greaterThanOrEqualTo(
|
|
||||||
root.get(FeedEntryStatus_.entryInserted), newerThan));
|
|
||||||
}
|
|
||||||
|
|
||||||
query.where(predicates.toArray(new Predicate[0]));
|
|
||||||
orderStatusesBy(query, root, order);
|
|
||||||
|
|
||||||
TypedQuery<FeedEntryStatus> q = em.createQuery(query);
|
|
||||||
limit(q, offset, limit);
|
|
||||||
setTimeout(q);
|
|
||||||
|
|
||||||
return lazyLoadContent(includeContent, q.getResultList());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Map between subscriptionId and unread count
|
* Map between subscriptionId and unread count
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("rawtypes")
|
public Map<Long, Long> getUnreadCount(List<FeedSubscription> subscriptions) {
|
||||||
public Map<Long, Long> getUnreadCount(User user) {
|
|
||||||
Map<Long, Long> map = Maps.newHashMap();
|
Map<Long, Long> map = Maps.newHashMap();
|
||||||
Query query = em.createNamedQuery("EntryStatus.unreadCounts");
|
for (FeedSubscription sub : subscriptions) {
|
||||||
query.setParameter("user", user);
|
map.put(sub.getId(), getUnreadCount(sub));
|
||||||
setTimeout(query);
|
|
||||||
List resultList = query.getResultList();
|
|
||||||
for (Object o : resultList) {
|
|
||||||
Object[] array = (Object[]) o;
|
|
||||||
map.put((Long) array[0], (Long) array[1]);
|
|
||||||
}
|
}
|
||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
@@ -320,11 +273,6 @@ public class FeedEntryStatusDAO extends GenericDAO<FeedEntryStatus> {
|
|||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void orderEntriesBy(CriteriaQuery<?> query,
|
|
||||||
Path<FeedFeedEntry> ffeJoin, ReadingOrder order) {
|
|
||||||
orderBy(query, ffeJoin.get(FeedFeedEntry_.entryUpdated), order);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void orderStatusesBy(CriteriaQuery<?> query,
|
private void orderStatusesBy(CriteriaQuery<?> query,
|
||||||
Path<FeedEntryStatus> statusJoin, ReadingOrder order) {
|
Path<FeedEntryStatus> statusJoin, ReadingOrder order) {
|
||||||
orderBy(query, statusJoin.get(FeedEntryStatus_.entryUpdated), order);
|
orderBy(query, statusJoin.get(FeedEntryStatus_.entryUpdated), order);
|
||||||
@@ -345,16 +293,10 @@ public class FeedEntryStatusDAO extends GenericDAO<FeedEntryStatus> {
|
|||||||
setTimeout(query, applicationSettingsService.get().getQueryTimeout());
|
setTimeout(query, applicationSettingsService.get().getQueryTimeout());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void markAllEntries(User user, Date olderThan) {
|
|
||||||
List<FeedEntryStatus> statuses = findAllUnread(user, null, -1, -1,
|
|
||||||
null, false);
|
|
||||||
markList(statuses, olderThan);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void markSubscriptionEntries(List<FeedSubscription> subscriptions,
|
public void markSubscriptionEntries(List<FeedSubscription> subscriptions,
|
||||||
Date olderThan) {
|
Date olderThan) {
|
||||||
List<FeedEntryStatus> statuses = findUnreadBySubscriptions(
|
List<FeedEntryStatus> statuses = findBySubscriptions(subscriptions,
|
||||||
subscriptions, null, -1, -1, null, false);
|
true, null, null, -1, -1, null, false);
|
||||||
markList(statuses, olderThan);
|
markList(statuses, olderThan);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -371,13 +313,8 @@ public class FeedEntryStatusDAO extends GenericDAO<FeedEntryStatus> {
|
|||||||
Date inserted = status.getEntry().getInserted();
|
Date inserted = status.getEntry().getInserted();
|
||||||
if (olderThan == null || inserted == null
|
if (olderThan == null || inserted == null
|
||||||
|| olderThan.after(inserted)) {
|
|| olderThan.after(inserted)) {
|
||||||
if (status.isStarred()) {
|
status.setRead(true);
|
||||||
status.setRead(true);
|
list.add(status);
|
||||||
list.add(status);
|
|
||||||
} else {
|
|
||||||
delete(status);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,8 +35,13 @@ public abstract class GenericDAO<T extends AbstractModel> {
|
|||||||
builder = em.getCriteriaBuilder();
|
builder = em.getCriteriaBuilder();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void saveOrUpdate(Collection<? extends AbstractModel> models) {
|
public Session getSession() {
|
||||||
Session session = em.unwrap(Session.class);
|
Session session = em.unwrap(Session.class);
|
||||||
|
return session;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void saveOrUpdate(Collection<? extends AbstractModel> models) {
|
||||||
|
Session session = getSession();
|
||||||
int i = 1;
|
int i = 1;
|
||||||
for (AbstractModel model : models) {
|
for (AbstractModel model : models) {
|
||||||
session.saveOrUpdate(model);
|
session.saveOrUpdate(model);
|
||||||
@@ -152,7 +157,7 @@ public abstract class GenericDAO<T extends AbstractModel> {
|
|||||||
query.unwrap(Query.class).setCacheable(true);
|
query.unwrap(Query.class).setCacheable(true);
|
||||||
return query;
|
return query;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void setTimeout(javax.persistence.Query query, int queryTimeout) {
|
protected void setTimeout(javax.persistence.Query query, int queryTimeout) {
|
||||||
if (queryTimeout > 0) {
|
if (queryTimeout > 0) {
|
||||||
query.setHint("javax.persistence.query.timeout", queryTimeout);
|
query.setHint("javax.persistence.query.timeout", queryTimeout);
|
||||||
|
|||||||
@@ -19,8 +19,8 @@ public class FeedEntryService {
|
|||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
FeedSubscriptionDAO feedSubscriptionDAO;
|
FeedSubscriptionDAO feedSubscriptionDAO;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
FeedEntryDAO feedEntryDAO;
|
FeedEntryDAO feedEntryDAO;
|
||||||
|
|
||||||
public void markEntry(User user, Long entryId, Long subscriptionId,
|
public void markEntry(User user, Long entryId, Long subscriptionId,
|
||||||
@@ -38,24 +38,8 @@ public class FeedEntryService {
|
|||||||
|
|
||||||
FeedEntryStatus status = feedEntryStatusDAO.getStatus(sub, entry);
|
FeedEntryStatus status = feedEntryStatusDAO.getStatus(sub, entry);
|
||||||
|
|
||||||
if (read) {
|
status.setRead(read);
|
||||||
if (status.getId() != null) {
|
feedEntryStatusDAO.saveOrUpdate(status);
|
||||||
if (status.isStarred()) {
|
|
||||||
status.setRead(true);
|
|
||||||
feedEntryStatusDAO.saveOrUpdate(status);
|
|
||||||
} else {
|
|
||||||
feedEntryStatusDAO.delete(status);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (status.getId() == null) {
|
|
||||||
status = new FeedEntryStatus(user, sub, entry);
|
|
||||||
status.setSubscription(sub);
|
|
||||||
}
|
|
||||||
status.setRead(false);
|
|
||||||
feedEntryStatusDAO.saveOrUpdate(status);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void starEntry(User user, Long entryId, Long subscriptionId,
|
public void starEntry(User user, Long entryId, Long subscriptionId,
|
||||||
@@ -74,23 +58,8 @@ public class FeedEntryService {
|
|||||||
|
|
||||||
FeedEntryStatus status = feedEntryStatusDAO.getStatus(sub, entry);
|
FeedEntryStatus status = feedEntryStatusDAO.getStatus(sub, entry);
|
||||||
|
|
||||||
if (!starred) {
|
status.setStarred(starred);
|
||||||
if (status.getId() != null) {
|
feedEntryStatusDAO.saveOrUpdate(status);
|
||||||
if (!status.isRead()) {
|
|
||||||
status.setStarred(false);
|
|
||||||
feedEntryStatusDAO.saveOrUpdate(status);
|
|
||||||
} else {
|
|
||||||
feedEntryStatusDAO.delete(status);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (status.getId() == null) {
|
|
||||||
status = new FeedEntryStatus(user, sub, entry);
|
|
||||||
status.setSubscription(sub);
|
|
||||||
status.setRead(true);
|
|
||||||
}
|
|
||||||
status.setStarred(true);
|
|
||||||
feedEntryStatusDAO.saveOrUpdate(status);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -113,7 +113,8 @@ public class FeedSubscriptionService {
|
|||||||
Map<Long, Long> map = cache.getUnreadCounts(user);
|
Map<Long, Long> map = cache.getUnreadCounts(user);
|
||||||
if (map == null) {
|
if (map == null) {
|
||||||
log.debug("unread count cache miss for {}", Models.getId(user));
|
log.debug("unread count cache miss for {}", Models.getId(user));
|
||||||
map = feedEntryStatusDAO.getUnreadCount(user);
|
List<FeedSubscription> subs = feedSubscriptionDAO.findAll(user);
|
||||||
|
map = feedEntryStatusDAO.getUnreadCount(subs);
|
||||||
cache.setUnreadCounts(user, map);
|
cache.setUnreadCounts(user, map);
|
||||||
}
|
}
|
||||||
return map;
|
return map;
|
||||||
|
|||||||
@@ -18,7 +18,6 @@ import com.commafeed.backend.feeds.FeedUtils;
|
|||||||
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.FeedEntryContent;
|
import com.commafeed.backend.model.FeedEntryContent;
|
||||||
import com.commafeed.backend.model.FeedEntryStatus;
|
|
||||||
import com.commafeed.backend.model.FeedFeedEntry;
|
import com.commafeed.backend.model.FeedFeedEntry;
|
||||||
import com.commafeed.backend.model.FeedSubscription;
|
import com.commafeed.backend.model.FeedSubscription;
|
||||||
import com.commafeed.backend.model.User;
|
import com.commafeed.backend.model.User;
|
||||||
@@ -72,20 +71,13 @@ public class FeedUpdateService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (update != null) {
|
if (update != null) {
|
||||||
List<FeedEntryStatus> statusUpdateList = Lists.newArrayList();
|
|
||||||
List<User> users = Lists.newArrayList();
|
List<User> users = Lists.newArrayList();
|
||||||
for (FeedSubscription sub : subscriptions) {
|
for (FeedSubscription sub : subscriptions) {
|
||||||
User user = sub.getUser();
|
users.add(sub.getUser());
|
||||||
FeedEntryStatus status = new FeedEntryStatus(user, sub, update);
|
|
||||||
status.setSubscription(sub);
|
|
||||||
statusUpdateList.add(status);
|
|
||||||
users.add(user);
|
|
||||||
}
|
}
|
||||||
cache.invalidateUserData(users.toArray(new User[0]));
|
cache.invalidateUserData(users.toArray(new User[0]));
|
||||||
feedEntryDAO.saveOrUpdate(update);
|
feedEntryDAO.saveOrUpdate(update);
|
||||||
feedEntryStatusDAO.saveOrUpdate(statusUpdateList);
|
|
||||||
em.persist(ffe);
|
em.persist(ffe);
|
||||||
metricsBean.entryUpdated(statusUpdateList.size());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -54,8 +54,9 @@ public class NextUnreadRedirectPage extends WebPage {
|
|||||||
List<FeedEntryStatus> statuses = null;
|
List<FeedEntryStatus> statuses = null;
|
||||||
if (StringUtils.isBlank(categoryId)
|
if (StringUtils.isBlank(categoryId)
|
||||||
|| CategoryREST.ALL.equals(categoryId)) {
|
|| CategoryREST.ALL.equals(categoryId)) {
|
||||||
statuses = feedEntryStatusDAO.findAllUnread(user, null, 0, 1,
|
List<FeedSubscription> subs = feedSubscriptionDAO.findAll(user);
|
||||||
order, true);
|
statuses = feedEntryStatusDAO.findBySubscriptions(subs, true, null,
|
||||||
|
null, 0, 1, order, true);
|
||||||
} else {
|
} else {
|
||||||
FeedCategory category = feedCategoryDAO.findById(user,
|
FeedCategory category = feedCategoryDAO.findById(user,
|
||||||
Long.valueOf(categoryId));
|
Long.valueOf(categoryId));
|
||||||
@@ -64,8 +65,8 @@ public class NextUnreadRedirectPage extends WebPage {
|
|||||||
.findAllChildrenCategories(user, category);
|
.findAllChildrenCategories(user, category);
|
||||||
List<FeedSubscription> subscriptions = feedSubscriptionDAO
|
List<FeedSubscription> subscriptions = feedSubscriptionDAO
|
||||||
.findByCategories(user, children);
|
.findByCategories(user, children);
|
||||||
statuses = feedEntryStatusDAO.findUnreadBySubscriptions(
|
statuses = feedEntryStatusDAO.findBySubscriptions(
|
||||||
subscriptions, null, 0, 1, order, true);
|
subscriptions, true, null, null, 0, 1, order, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -106,16 +106,11 @@ public class CategoryREST extends AbstractResourceREST {
|
|||||||
|
|
||||||
if (ALL.equals(id)) {
|
if (ALL.equals(id)) {
|
||||||
entries.setName("All");
|
entries.setName("All");
|
||||||
List<FeedEntryStatus> list = null;
|
|
||||||
List<FeedSubscription> subscriptions = feedSubscriptionDAO
|
List<FeedSubscription> subscriptions = feedSubscriptionDAO
|
||||||
.findAll(getUser());
|
.findAll(getUser());
|
||||||
if (unreadOnly) {
|
List<FeedEntryStatus> list = feedEntryStatusDAO
|
||||||
list = feedEntryStatusDAO.findAllUnread(getUser(),
|
.findBySubscriptions(subscriptions, unreadOnly, null,
|
||||||
newerThanDate, offset, limit + 1, order, true);
|
newerThanDate, offset, limit + 1, order, true);
|
||||||
} else {
|
|
||||||
list = feedEntryStatusDAO.findBySubscriptions(subscriptions,
|
|
||||||
null, newerThanDate, offset, limit + 1, order, true);
|
|
||||||
}
|
|
||||||
for (FeedEntryStatus status : list) {
|
for (FeedEntryStatus status : list) {
|
||||||
entries.getEntries().add(
|
entries.getEntries().add(
|
||||||
Entry.build(status, applicationSettingsService.get()
|
Entry.build(status, applicationSettingsService.get()
|
||||||
@@ -141,14 +136,9 @@ public class CategoryREST extends AbstractResourceREST {
|
|||||||
.findAllChildrenCategories(getUser(), parent);
|
.findAllChildrenCategories(getUser(), parent);
|
||||||
List<FeedSubscription> subs = feedSubscriptionDAO
|
List<FeedSubscription> subs = feedSubscriptionDAO
|
||||||
.findByCategories(getUser(), categories);
|
.findByCategories(getUser(), categories);
|
||||||
List<FeedEntryStatus> list = null;
|
List<FeedEntryStatus> list = feedEntryStatusDAO
|
||||||
if (unreadOnly) {
|
.findBySubscriptions(subs, unreadOnly, null,
|
||||||
list = feedEntryStatusDAO.findUnreadBySubscriptions(subs,
|
newerThanDate, offset, limit + 1, order, true);
|
||||||
newerThanDate, offset, limit + 1, order, true);
|
|
||||||
} else {
|
|
||||||
list = feedEntryStatusDAO.findBySubscriptions(subs, null,
|
|
||||||
newerThanDate, offset, limit + 1, order, true);
|
|
||||||
}
|
|
||||||
for (FeedEntryStatus status : list) {
|
for (FeedEntryStatus status : list) {
|
||||||
entries.getEntries().add(
|
entries.getEntries().add(
|
||||||
Entry.build(status, applicationSettingsService
|
Entry.build(status, applicationSettingsService
|
||||||
@@ -225,7 +215,10 @@ public class CategoryREST extends AbstractResourceREST {
|
|||||||
req.getOlderThan());
|
req.getOlderThan());
|
||||||
|
|
||||||
if (ALL.equals(req.getId())) {
|
if (ALL.equals(req.getId())) {
|
||||||
feedEntryStatusDAO.markAllEntries(getUser(), olderThan);
|
List<FeedSubscription> subscriptions = feedSubscriptionDAO
|
||||||
|
.findAll(getUser());
|
||||||
|
feedEntryStatusDAO
|
||||||
|
.markSubscriptionEntries(subscriptions, olderThan);
|
||||||
} else if (STARRED.equals(req.getId())) {
|
} else if (STARRED.equals(req.getId())) {
|
||||||
feedEntryStatusDAO.markStarredEntries(getUser(), olderThan);
|
feedEntryStatusDAO.markStarredEntries(getUser(), olderThan);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -108,8 +108,8 @@ public class EntryREST extends AbstractResourceREST {
|
|||||||
List<Entry> list = Lists.newArrayList();
|
List<Entry> list = Lists.newArrayList();
|
||||||
List<FeedSubscription> subs = feedSubscriptionDAO.findAll(getUser());
|
List<FeedSubscription> subs = feedSubscriptionDAO.findAll(getUser());
|
||||||
List<FeedEntryStatus> entriesStatus = feedEntryStatusDAO
|
List<FeedEntryStatus> entriesStatus = feedEntryStatusDAO
|
||||||
.findBySubscriptions(subs, keywords, null, offset, limit,
|
.findBySubscriptions(subs, false, keywords, null, offset,
|
||||||
ReadingOrder.desc, true);
|
limit, ReadingOrder.desc, true);
|
||||||
for (FeedEntryStatus status : entriesStatus) {
|
for (FeedEntryStatus status : entriesStatus) {
|
||||||
list.add(Entry.build(status, applicationSettingsService.get()
|
list.add(Entry.build(status, applicationSettingsService.get()
|
||||||
.getPublicUrl(), applicationSettingsService.get()
|
.getPublicUrl(), applicationSettingsService.get()
|
||||||
|
|||||||
@@ -152,16 +152,10 @@ public class FeedREST extends AbstractResourceREST {
|
|||||||
entries.setErrorCount(subscription.getFeed().getErrorCount());
|
entries.setErrorCount(subscription.getFeed().getErrorCount());
|
||||||
entries.setFeedLink(subscription.getFeed().getLink());
|
entries.setFeedLink(subscription.getFeed().getLink());
|
||||||
|
|
||||||
List<FeedEntryStatus> list = null;
|
List<FeedEntryStatus> list = feedEntryStatusDAO
|
||||||
if (unreadOnly) {
|
.findBySubscriptions(Arrays.asList(subscription),
|
||||||
list = feedEntryStatusDAO.findUnreadBySubscriptions(
|
unreadOnly, null, newerThanDate, offset, limit + 1,
|
||||||
Arrays.asList(subscription), newerThanDate, offset,
|
order, true);
|
||||||
limit + 1, order, true);
|
|
||||||
} else {
|
|
||||||
list = feedEntryStatusDAO.findBySubscriptions(
|
|
||||||
Arrays.asList(subscription), null, newerThanDate,
|
|
||||||
offset, limit + 1, order, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (FeedEntryStatus status : list) {
|
for (FeedEntryStatus status : list) {
|
||||||
entries.getEntries().add(
|
entries.getEntries().add(
|
||||||
|
|||||||
Reference in New Issue
Block a user