added optional 'onlyIds' api parameter

This commit is contained in:
Athou
2013-08-09 12:53:21 +02:00
parent 677fb87f71
commit f8738f10af
6 changed files with 44 additions and 34 deletions

View File

@@ -125,7 +125,7 @@ public class FeedEntryStatusDAO extends GenericDAO<FeedEntryStatus> {
}
private Criteria buildSearchCriteria(FeedSubscription sub, boolean unreadOnly, String keywords, Date newerThan, int offset, int limit,
ReadingOrder order, boolean includeContent, Date last) {
ReadingOrder order, Date last) {
Criteria criteria = getSession().createCriteria(FeedEntry.class, ALIAS_ENTRY);
criteria.add(Restrictions.eq(FeedEntry_.feed.getName(), sub.getFeed()));
@@ -192,15 +192,14 @@ public class FeedEntryStatusDAO extends GenericDAO<FeedEntryStatus> {
}
@SuppressWarnings("unchecked")
public List<FeedEntryStatus> findBySubscriptions(List<FeedSubscription> subscriptions, boolean unreadOnly, String keywords,
Date newerThan, int offset, int limit, ReadingOrder order, boolean includeContent) {
public List<FeedEntryStatus> findBySubscriptions(List<FeedSubscription> subs, boolean unreadOnly, String keywords, Date newerThan,
int offset, int limit, ReadingOrder order, boolean includeContent, boolean onlyIds) {
int capacity = offset + limit;
Comparator<FeedEntryStatus> comparator = order == ReadingOrder.desc ? STATUS_COMPARATOR_DESC : STATUS_COMPARATOR_ASC;
FixedSizeSortedSet<FeedEntryStatus> set = new FixedSizeSortedSet<FeedEntryStatus>(capacity, comparator);
for (FeedSubscription sub : subscriptions) {
for (FeedSubscription sub : subs) {
Date last = (order != null && set.isFull()) ? set.last().getEntryUpdated() : null;
Criteria criteria = buildSearchCriteria(sub, unreadOnly, keywords, newerThan, -1, capacity, order, includeContent, last);
Criteria criteria = buildSearchCriteria(sub, unreadOnly, keywords, newerThan, -1, capacity, order, last);
ProjectionList projection = Projections.projectionList();
projection.add(Projections.property("id"), "id");
projection.add(Projections.property("updated"), "updated");
@@ -232,18 +231,21 @@ public class FeedEntryStatusDAO extends GenericDAO<FeedEntryStatus> {
statusPlaceholders = statusPlaceholders.subList(Math.max(offset, 0), size);
List<FeedEntryStatus> statuses = Lists.newArrayList();
for (FeedEntryStatus status : statusPlaceholders) {
FeedEntry entry = em.find(FeedEntry.class, status.getEntry().getId());
statuses.add(getStatus(status.getSubscription(), entry));
if (!onlyIds) {
List<FeedEntryStatus> statuses = Lists.newArrayList();
for (FeedEntryStatus status : statusPlaceholders) {
FeedEntry entry = em.find(FeedEntry.class, status.getEntry().getId());
statuses.add(getStatus(status.getSubscription(), entry));
}
statusPlaceholders = lazyLoadContent(includeContent, statuses);
}
return lazyLoadContent(includeContent, statuses);
return statusPlaceholders;
}
@SuppressWarnings("unchecked")
public UnreadCount getUnreadCount(FeedSubscription subscription) {
UnreadCount uc = null;
Criteria criteria = buildSearchCriteria(subscription, true, null, null, -1, -1, null, false, null);
Criteria criteria = buildSearchCriteria(subscription, true, null, null, -1, -1, null, null);
ProjectionList projection = Projections.projectionList();
projection.add(Projections.rowCount(), "count");
projection.add(Projections.max(FeedEntry_.updated.getName()), "updated");

View File

@@ -69,7 +69,7 @@ public class FeedEntryService {
}
public void markSubscriptionEntries(User user, List<FeedSubscription> subscriptions, Date olderThan) {
List<FeedEntryStatus> statuses = feedEntryStatusDAO.findBySubscriptions(subscriptions, true, null, null, -1, -1, null, false);
List<FeedEntryStatus> statuses = feedEntryStatusDAO.findBySubscriptions(subscriptions, true, null, null, -1, -1, null, false, false);
markList(statuses, olderThan);
cache.invalidateUnreadCount(subscriptions.toArray(new FeedSubscription[0]));
cache.invalidateUserRootCategory(user);

View File

@@ -10,6 +10,7 @@ import javax.xml.bind.annotation.XmlRootElement;
import com.commafeed.backend.feeds.FeedUtils;
import com.commafeed.backend.model.FeedEntry;
import com.commafeed.backend.model.FeedEntryContent;
import com.commafeed.backend.model.FeedEntryStatus;
import com.commafeed.backend.model.FeedSubscription;
import com.sun.syndication.feed.synd.SyndContentImpl;
@@ -29,29 +30,31 @@ public class Entry implements Serializable {
FeedEntry feedEntry = status.getEntry();
FeedSubscription sub = status.getSubscription();
entry.setRead(status.isRead());
entry.setStarred(status.isStarred());
entry.setMarkable(status.isMarkable());
FeedEntryContent content = feedEntry.getContent();
entry.setId(String.valueOf(feedEntry.getId()));
entry.setGuid(feedEntry.getGuid());
entry.setTitle(feedEntry.getContent().getTitle());
entry.setContent(FeedUtils.proxyImages(feedEntry.getContent().getContent(), publicUrl, proxyImages));
entry.setRtl(FeedUtils.isRTL(feedEntry));
entry.setAuthor(feedEntry.getContent().getAuthor());
entry.setEnclosureUrl(feedEntry.getContent().getEnclosureUrl());
entry.setEnclosureType(feedEntry.getContent().getEnclosureType());
entry.setRead(status.isRead());
entry.setStarred(status.isStarred());
entry.setMarkable(status.isMarkable());
entry.setDate(feedEntry.getUpdated());
entry.setInsertedDate(feedEntry.getInserted());
entry.setUrl(feedEntry.getUrl());
entry.setFeedName(sub.getTitle());
entry.setFeedId(String.valueOf(sub.getId()));
entry.setFeedUrl(sub.getFeed().getUrl());
entry.setFeedLink(sub.getFeed().getLink());
entry.setIconUrl(FeedUtils.getFaviconUrl(sub, publicUrl));
if (content != null) {
entry.setRtl(FeedUtils.isRTL(feedEntry));
entry.setTitle(content.getTitle());
entry.setContent(FeedUtils.proxyImages(content.getContent(), publicUrl, proxyImages));
entry.setAuthor(content.getAuthor());
entry.setEnclosureUrl(content.getEnclosureUrl());
entry.setEnclosureType(content.getEnclosureType());
}
return entry;
}

View File

@@ -54,13 +54,13 @@ public class NextUnreadRedirectPage extends WebPage {
List<FeedEntryStatus> statuses = null;
if (StringUtils.isBlank(categoryId) || CategoryREST.ALL.equals(categoryId)) {
List<FeedSubscription> subs = feedSubscriptionDAO.findAll(user);
statuses = feedEntryStatusDAO.findBySubscriptions(subs, true, null, null, 0, 1, order, true);
statuses = feedEntryStatusDAO.findBySubscriptions(subs, true, null, null, 0, 1, order, true, false);
} else {
FeedCategory category = feedCategoryDAO.findById(user, Long.valueOf(categoryId));
if (category != null) {
List<FeedCategory> children = feedCategoryDAO.findAllChildrenCategories(user, category);
List<FeedSubscription> subscriptions = feedSubscriptionDAO.findByCategories(user, children);
statuses = feedEntryStatusDAO.findBySubscriptions(subscriptions, true, null, null, 0, 1, order, true);
statuses = feedEntryStatusDAO.findBySubscriptions(subscriptions, true, null, null, 0, 1, order, true, false);
}
}

View File

@@ -106,7 +106,8 @@ public class CategoryREST extends AbstractREST {
value = "date ordering",
allowableValues = "asc,desc") @QueryParam("order") @DefaultValue("desc") ReadingOrder order, @ApiParam(
value = "keywords separated by spaces, 3 characters minimum",
required = true) @QueryParam("keywords") String keywords) {
required = true) @QueryParam("keywords") String keywords,
@ApiParam(value = "return only entry ids") @DefaultValue("false") @QueryParam("onlyIds") boolean onlyIds) {
Preconditions.checkNotNull(readType);
@@ -130,7 +131,8 @@ public class CategoryREST extends AbstractREST {
entries.setName("All");
List<FeedSubscription> subscriptions = feedSubscriptionDAO.findAll(getUser());
List<FeedEntryStatus> list = feedEntryStatusDAO.findBySubscriptions(subscriptions, unreadOnly, keywords, newerThanDate, offset,
limit + 1, order, true);
limit + 1, order, true, onlyIds);
for (FeedEntryStatus status : list) {
entries.getEntries().add(
Entry.build(status, applicationSettingsService.get().getPublicUrl(), applicationSettingsService.get()
@@ -139,7 +141,7 @@ public class CategoryREST extends AbstractREST {
} else if (STARRED.equals(id)) {
entries.setName("Starred");
List<FeedEntryStatus> starred = feedEntryStatusDAO.findStarred(getUser(), newerThanDate, offset, limit + 1, order, true);
List<FeedEntryStatus> starred = feedEntryStatusDAO.findStarred(getUser(), newerThanDate, offset, limit + 1, order, !onlyIds);
for (FeedEntryStatus status : starred) {
entries.getEntries().add(
Entry.build(status, applicationSettingsService.get().getPublicUrl(), applicationSettingsService.get()
@@ -150,8 +152,10 @@ public class CategoryREST extends AbstractREST {
if (parent != null) {
List<FeedCategory> categories = feedCategoryDAO.findAllChildrenCategories(getUser(), parent);
List<FeedSubscription> subs = feedSubscriptionDAO.findByCategories(getUser(), categories);
List<FeedEntryStatus> list = feedEntryStatusDAO.findBySubscriptions(subs, unreadOnly, keywords, newerThanDate, offset,
limit + 1, order, true);
limit + 1, order, true, onlyIds);
for (FeedEntryStatus status : list) {
entries.getEntries().add(
Entry.build(status, applicationSettingsService.get().getPublicUrl(), applicationSettingsService.get()
@@ -188,7 +192,7 @@ public class CategoryREST extends AbstractREST {
int offset = 0;
int limit = 20;
Entries entries = (Entries) getCategoryEntries(id, readType, null, offset, limit, order, null).getEntity();
Entries entries = (Entries) getCategoryEntries(id, readType, null, offset, limit, order, null, false).getEntity();
SyndFeed feed = new SyndFeedImpl();
feed.setFeedType("rss_2.0");

View File

@@ -143,7 +143,8 @@ public class FeedREST extends AbstractREST {
value = "date ordering",
allowableValues = "asc,desc") @QueryParam("order") @DefaultValue("desc") ReadingOrder order, @ApiParam(
value = "keywords separated by spaces, 3 characters minimum",
required = true) @QueryParam("keywords") String keywords) {
required = true) @QueryParam("keywords") String keywords,
@ApiParam(value = "return only entry ids") @DefaultValue("false") @QueryParam("onlyIds") boolean onlyIds) {
Preconditions.checkNotNull(id);
Preconditions.checkNotNull(readType);
@@ -170,7 +171,7 @@ public class FeedREST extends AbstractREST {
entries.setFeedLink(subscription.getFeed().getLink());
List<FeedEntryStatus> list = feedEntryStatusDAO.findBySubscriptions(Arrays.asList(subscription), unreadOnly, keywords,
newerThanDate, offset, limit + 1, order, true);
newerThanDate, offset, limit + 1, order, true, onlyIds);
for (FeedEntryStatus status : list) {
entries.getEntries().add(
@@ -204,7 +205,7 @@ public class FeedREST extends AbstractREST {
int offset = 0;
int limit = 20;
Entries entries = (Entries) getFeedEntries(id, readType, null, offset, limit, order, null).getEntity();
Entries entries = (Entries) getFeedEntries(id, readType, null, offset, limit, order, null, false).getEntity();
SyndFeed feed = new SyndFeedImpl();
feed.setFeedType("rss_2.0");