forked from Archives/Athou_commafeed
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.TypedQuery;
|
||||
import javax.persistence.criteria.CriteriaQuery;
|
||||
import javax.persistence.criteria.Join;
|
||||
import javax.persistence.criteria.Path;
|
||||
import javax.persistence.criteria.Predicate;
|
||||
import javax.persistence.criteria.Root;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
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.LoggerFactory;
|
||||
|
||||
import com.commafeed.backend.FixedSizeSortedSet;
|
||||
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.FeedEntryStatus_;
|
||||
import com.commafeed.backend.model.FeedEntry_;
|
||||
import com.commafeed.backend.model.FeedFeedEntry;
|
||||
import com.commafeed.backend.model.FeedFeedEntry_;
|
||||
import com.commafeed.backend.model.FeedSubscription;
|
||||
import com.commafeed.backend.model.Models;
|
||||
import com.commafeed.backend.model.User;
|
||||
import com.commafeed.backend.model.UserSettings.ReadingOrder;
|
||||
import com.commafeed.backend.services.ApplicationSettingsService;
|
||||
import com.google.api.client.util.Maps;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
|
||||
@Stateless
|
||||
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
|
||||
ApplicationSettingsService applicationSettingsService;
|
||||
|
||||
@@ -90,7 +81,7 @@ public class FeedEntryStatusDAO extends GenericDAO<FeedEntryStatus> {
|
||||
FeedEntryStatus status = Iterables.getFirst(statuses, null);
|
||||
if (status == null) {
|
||||
status = new FeedEntryStatus(sub.getUser(), sub, entry);
|
||||
status.setRead(true);
|
||||
status.setRead(false);
|
||||
}
|
||||
return status;
|
||||
}
|
||||
@@ -120,10 +111,94 @@ public class FeedEntryStatusDAO extends GenericDAO<FeedEntryStatus> {
|
||||
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(
|
||||
List<FeedSubscription> subscriptions, String keywords,
|
||||
Date newerThan, int offset, int limit, ReadingOrder order,
|
||||
boolean includeContent) {
|
||||
List<FeedSubscription> subscriptions, boolean unreadOnly,
|
||||
String keywords, Date newerThan, int offset, int limit,
|
||||
ReadingOrder order, boolean includeContent) {
|
||||
|
||||
int capacity = offset + limit;
|
||||
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>(
|
||||
capacity < 0 ? Integer.MAX_VALUE : capacity, comparator);
|
||||
for (FeedSubscription sub : subscriptions) {
|
||||
CriteriaQuery<FeedEntry> query = builder
|
||||
.createQuery(FeedEntry.class);
|
||||
Root<FeedEntry> root = query.from(FeedEntry.class);
|
||||
Join<FeedEntry, FeedFeedEntry> ffeJoin = root
|
||||
.join(FeedEntry_.feedRelationships);
|
||||
FeedEntry last = (order != null && set.isFull()) ? set.last()
|
||||
: null;
|
||||
Criteria criteria = buildSearchCriteria(sub, unreadOnly, keywords,
|
||||
newerThan, -1, limit, order, includeContent, last);
|
||||
|
||||
List<Predicate> predicates = Lists.newArrayList();
|
||||
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();
|
||||
List<FeedEntry> list = criteria.list();
|
||||
for (FeedEntry entry : list) {
|
||||
entry.setSubscription(sub);
|
||||
}
|
||||
@@ -206,105 +235,29 @@ public class FeedEntryStatusDAO extends GenericDAO<FeedEntryStatus> {
|
||||
return lazyLoadContent(includeContent, results);
|
||||
}
|
||||
|
||||
public List<FeedEntryStatus> findUnreadBySubscriptions(
|
||||
List<FeedSubscription> subscriptions, Date newerThan, int offset,
|
||||
int limit, ReadingOrder order, boolean includeContent) {
|
||||
|
||||
int capacity = offset + limit;
|
||||
Comparator<FeedEntryStatus> comparator = order == ReadingOrder.desc ? STATUS_COMPARATOR_DESC
|
||||
: STATUS_COMPARATOR_ASC;
|
||||
FixedSizeSortedSet<FeedEntryStatus> set = new FixedSizeSortedSet<FeedEntryStatus>(
|
||||
capacity < 0 ? Integer.MAX_VALUE : capacity, comparator);
|
||||
for (FeedSubscription sub : subscriptions) {
|
||||
CriteriaQuery<FeedEntryStatus> query = builder
|
||||
.createQuery(getType());
|
||||
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);
|
||||
@SuppressWarnings("unchecked")
|
||||
public Long getUnreadCount(FeedSubscription subscription) {
|
||||
Long count = null;
|
||||
Criteria criteria = buildSearchCriteria(subscription, true, null, null,
|
||||
-1, -1, null, false, null);
|
||||
ProjectionList projection = Projections.projectionList();
|
||||
projection.add(Projections.rowCount(), "count");
|
||||
criteria.setProjection(projection);
|
||||
criteria.setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP);
|
||||
List<Map<String, Long>> list = criteria.list();
|
||||
for (Map<String, Long> row : list) {
|
||||
count = row.get("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());
|
||||
return count;
|
||||
}
|
||||
|
||||
/**
|
||||
* Map between subscriptionId and unread count
|
||||
*/
|
||||
@SuppressWarnings("rawtypes")
|
||||
public Map<Long, Long> getUnreadCount(User user) {
|
||||
public Map<Long, Long> getUnreadCount(List<FeedSubscription> subscriptions) {
|
||||
Map<Long, Long> map = Maps.newHashMap();
|
||||
Query query = em.createNamedQuery("EntryStatus.unreadCounts");
|
||||
query.setParameter("user", user);
|
||||
setTimeout(query);
|
||||
List resultList = query.getResultList();
|
||||
for (Object o : resultList) {
|
||||
Object[] array = (Object[]) o;
|
||||
map.put((Long) array[0], (Long) array[1]);
|
||||
for (FeedSubscription sub : subscriptions) {
|
||||
map.put(sub.getId(), getUnreadCount(sub));
|
||||
}
|
||||
return map;
|
||||
}
|
||||
@@ -320,11 +273,6 @@ public class FeedEntryStatusDAO extends GenericDAO<FeedEntryStatus> {
|
||||
return results;
|
||||
}
|
||||
|
||||
private void orderEntriesBy(CriteriaQuery<?> query,
|
||||
Path<FeedFeedEntry> ffeJoin, ReadingOrder order) {
|
||||
orderBy(query, ffeJoin.get(FeedFeedEntry_.entryUpdated), order);
|
||||
}
|
||||
|
||||
private void orderStatusesBy(CriteriaQuery<?> query,
|
||||
Path<FeedEntryStatus> statusJoin, ReadingOrder order) {
|
||||
orderBy(query, statusJoin.get(FeedEntryStatus_.entryUpdated), order);
|
||||
@@ -345,16 +293,10 @@ public class FeedEntryStatusDAO extends GenericDAO<FeedEntryStatus> {
|
||||
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,
|
||||
Date olderThan) {
|
||||
List<FeedEntryStatus> statuses = findUnreadBySubscriptions(
|
||||
subscriptions, null, -1, -1, null, false);
|
||||
List<FeedEntryStatus> statuses = findBySubscriptions(subscriptions,
|
||||
true, null, null, -1, -1, null, false);
|
||||
markList(statuses, olderThan);
|
||||
}
|
||||
|
||||
@@ -371,13 +313,8 @@ public class FeedEntryStatusDAO extends GenericDAO<FeedEntryStatus> {
|
||||
Date inserted = status.getEntry().getInserted();
|
||||
if (olderThan == null || inserted == null
|
||||
|| olderThan.after(inserted)) {
|
||||
if (status.isStarred()) {
|
||||
status.setRead(true);
|
||||
list.add(status);
|
||||
} else {
|
||||
delete(status);
|
||||
}
|
||||
|
||||
status.setRead(true);
|
||||
list.add(status);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,8 +35,13 @@ public abstract class GenericDAO<T extends AbstractModel> {
|
||||
builder = em.getCriteriaBuilder();
|
||||
}
|
||||
|
||||
public void saveOrUpdate(Collection<? extends AbstractModel> models) {
|
||||
public Session getSession() {
|
||||
Session session = em.unwrap(Session.class);
|
||||
return session;
|
||||
}
|
||||
|
||||
public void saveOrUpdate(Collection<? extends AbstractModel> models) {
|
||||
Session session = getSession();
|
||||
int i = 1;
|
||||
for (AbstractModel model : models) {
|
||||
session.saveOrUpdate(model);
|
||||
@@ -152,7 +157,7 @@ public abstract class GenericDAO<T extends AbstractModel> {
|
||||
query.unwrap(Query.class).setCacheable(true);
|
||||
return query;
|
||||
}
|
||||
|
||||
|
||||
protected void setTimeout(javax.persistence.Query query, int queryTimeout) {
|
||||
if (queryTimeout > 0) {
|
||||
query.setHint("javax.persistence.query.timeout", queryTimeout);
|
||||
|
||||
@@ -19,8 +19,8 @@ public class FeedEntryService {
|
||||
|
||||
@Inject
|
||||
FeedSubscriptionDAO feedSubscriptionDAO;
|
||||
|
||||
@Inject
|
||||
|
||||
@Inject
|
||||
FeedEntryDAO feedEntryDAO;
|
||||
|
||||
public void markEntry(User user, Long entryId, Long subscriptionId,
|
||||
@@ -38,24 +38,8 @@ public class FeedEntryService {
|
||||
|
||||
FeedEntryStatus status = feedEntryStatusDAO.getStatus(sub, entry);
|
||||
|
||||
if (read) {
|
||||
if (status.getId() != null) {
|
||||
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);
|
||||
}
|
||||
|
||||
status.setRead(read);
|
||||
feedEntryStatusDAO.saveOrUpdate(status);
|
||||
}
|
||||
|
||||
public void starEntry(User user, Long entryId, Long subscriptionId,
|
||||
@@ -74,23 +58,8 @@ public class FeedEntryService {
|
||||
|
||||
FeedEntryStatus status = feedEntryStatusDAO.getStatus(sub, entry);
|
||||
|
||||
if (!starred) {
|
||||
if (status.getId() != null) {
|
||||
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);
|
||||
}
|
||||
status.setStarred(starred);
|
||||
feedEntryStatusDAO.saveOrUpdate(status);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -113,7 +113,8 @@ public class FeedSubscriptionService {
|
||||
Map<Long, Long> map = cache.getUnreadCounts(user);
|
||||
if (map == null) {
|
||||
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);
|
||||
}
|
||||
return map;
|
||||
|
||||
@@ -18,7 +18,6 @@ import com.commafeed.backend.feeds.FeedUtils;
|
||||
import com.commafeed.backend.model.Feed;
|
||||
import com.commafeed.backend.model.FeedEntry;
|
||||
import com.commafeed.backend.model.FeedEntryContent;
|
||||
import com.commafeed.backend.model.FeedEntryStatus;
|
||||
import com.commafeed.backend.model.FeedFeedEntry;
|
||||
import com.commafeed.backend.model.FeedSubscription;
|
||||
import com.commafeed.backend.model.User;
|
||||
@@ -72,20 +71,13 @@ public class FeedUpdateService {
|
||||
}
|
||||
|
||||
if (update != null) {
|
||||
List<FeedEntryStatus> statusUpdateList = Lists.newArrayList();
|
||||
List<User> users = Lists.newArrayList();
|
||||
for (FeedSubscription sub : subscriptions) {
|
||||
User user = sub.getUser();
|
||||
FeedEntryStatus status = new FeedEntryStatus(user, sub, update);
|
||||
status.setSubscription(sub);
|
||||
statusUpdateList.add(status);
|
||||
users.add(user);
|
||||
users.add(sub.getUser());
|
||||
}
|
||||
cache.invalidateUserData(users.toArray(new User[0]));
|
||||
feedEntryDAO.saveOrUpdate(update);
|
||||
feedEntryStatusDAO.saveOrUpdate(statusUpdateList);
|
||||
em.persist(ffe);
|
||||
metricsBean.entryUpdated(statusUpdateList.size());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,8 +54,9 @@ public class NextUnreadRedirectPage extends WebPage {
|
||||
List<FeedEntryStatus> statuses = null;
|
||||
if (StringUtils.isBlank(categoryId)
|
||||
|| CategoryREST.ALL.equals(categoryId)) {
|
||||
statuses = feedEntryStatusDAO.findAllUnread(user, null, 0, 1,
|
||||
order, true);
|
||||
List<FeedSubscription> subs = feedSubscriptionDAO.findAll(user);
|
||||
statuses = feedEntryStatusDAO.findBySubscriptions(subs, true, null,
|
||||
null, 0, 1, order, true);
|
||||
} else {
|
||||
FeedCategory category = feedCategoryDAO.findById(user,
|
||||
Long.valueOf(categoryId));
|
||||
@@ -64,8 +65,8 @@ public class NextUnreadRedirectPage extends WebPage {
|
||||
.findAllChildrenCategories(user, category);
|
||||
List<FeedSubscription> subscriptions = feedSubscriptionDAO
|
||||
.findByCategories(user, children);
|
||||
statuses = feedEntryStatusDAO.findUnreadBySubscriptions(
|
||||
subscriptions, null, 0, 1, order, true);
|
||||
statuses = feedEntryStatusDAO.findBySubscriptions(
|
||||
subscriptions, true, null, null, 0, 1, order, true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -106,16 +106,11 @@ public class CategoryREST extends AbstractResourceREST {
|
||||
|
||||
if (ALL.equals(id)) {
|
||||
entries.setName("All");
|
||||
List<FeedEntryStatus> list = null;
|
||||
List<FeedSubscription> subscriptions = feedSubscriptionDAO
|
||||
.findAll(getUser());
|
||||
if (unreadOnly) {
|
||||
list = feedEntryStatusDAO.findAllUnread(getUser(),
|
||||
newerThanDate, offset, limit + 1, order, true);
|
||||
} else {
|
||||
list = feedEntryStatusDAO.findBySubscriptions(subscriptions,
|
||||
null, newerThanDate, offset, limit + 1, order, true);
|
||||
}
|
||||
List<FeedEntryStatus> list = feedEntryStatusDAO
|
||||
.findBySubscriptions(subscriptions, unreadOnly, null,
|
||||
newerThanDate, offset, limit + 1, order, true);
|
||||
for (FeedEntryStatus status : list) {
|
||||
entries.getEntries().add(
|
||||
Entry.build(status, applicationSettingsService.get()
|
||||
@@ -141,14 +136,9 @@ public class CategoryREST extends AbstractResourceREST {
|
||||
.findAllChildrenCategories(getUser(), parent);
|
||||
List<FeedSubscription> subs = feedSubscriptionDAO
|
||||
.findByCategories(getUser(), categories);
|
||||
List<FeedEntryStatus> list = null;
|
||||
if (unreadOnly) {
|
||||
list = feedEntryStatusDAO.findUnreadBySubscriptions(subs,
|
||||
newerThanDate, offset, limit + 1, order, true);
|
||||
} else {
|
||||
list = feedEntryStatusDAO.findBySubscriptions(subs, null,
|
||||
newerThanDate, offset, limit + 1, order, true);
|
||||
}
|
||||
List<FeedEntryStatus> list = feedEntryStatusDAO
|
||||
.findBySubscriptions(subs, unreadOnly, null,
|
||||
newerThanDate, offset, limit + 1, order, true);
|
||||
for (FeedEntryStatus status : list) {
|
||||
entries.getEntries().add(
|
||||
Entry.build(status, applicationSettingsService
|
||||
@@ -225,7 +215,10 @@ public class CategoryREST extends AbstractResourceREST {
|
||||
req.getOlderThan());
|
||||
|
||||
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())) {
|
||||
feedEntryStatusDAO.markStarredEntries(getUser(), olderThan);
|
||||
} else {
|
||||
|
||||
@@ -108,8 +108,8 @@ public class EntryREST extends AbstractResourceREST {
|
||||
List<Entry> list = Lists.newArrayList();
|
||||
List<FeedSubscription> subs = feedSubscriptionDAO.findAll(getUser());
|
||||
List<FeedEntryStatus> entriesStatus = feedEntryStatusDAO
|
||||
.findBySubscriptions(subs, keywords, null, offset, limit,
|
||||
ReadingOrder.desc, true);
|
||||
.findBySubscriptions(subs, false, keywords, null, offset,
|
||||
limit, ReadingOrder.desc, true);
|
||||
for (FeedEntryStatus status : entriesStatus) {
|
||||
list.add(Entry.build(status, applicationSettingsService.get()
|
||||
.getPublicUrl(), applicationSettingsService.get()
|
||||
|
||||
@@ -152,16 +152,10 @@ public class FeedREST extends AbstractResourceREST {
|
||||
entries.setErrorCount(subscription.getFeed().getErrorCount());
|
||||
entries.setFeedLink(subscription.getFeed().getLink());
|
||||
|
||||
List<FeedEntryStatus> list = null;
|
||||
if (unreadOnly) {
|
||||
list = feedEntryStatusDAO.findUnreadBySubscriptions(
|
||||
Arrays.asList(subscription), newerThanDate, offset,
|
||||
limit + 1, order, true);
|
||||
} else {
|
||||
list = feedEntryStatusDAO.findBySubscriptions(
|
||||
Arrays.asList(subscription), null, newerThanDate,
|
||||
offset, limit + 1, order, true);
|
||||
}
|
||||
List<FeedEntryStatus> list = feedEntryStatusDAO
|
||||
.findBySubscriptions(Arrays.asList(subscription),
|
||||
unreadOnly, null, newerThanDate, offset, limit + 1,
|
||||
order, true);
|
||||
|
||||
for (FeedEntryStatus status : list) {
|
||||
entries.getEntries().add(
|
||||
|
||||
Reference in New Issue
Block a user