return count only (fixes #18)

This commit is contained in:
Athou
2013-04-06 17:21:48 +02:00
parent 4cb77f5a73
commit 56443490b7
4 changed files with 16 additions and 6 deletions

View File

@@ -112,6 +112,14 @@ public class FeedEntryService extends GenericDAO<FeedEntry> {
return buildList(query.getResultList());
}
public Long getUnreadCount(Feed feed, User user) {
TypedQuery<Long> query = em.createNamedQuery("Entry.unreadByFeedCount",
Long.class);
query.setParameter("feed", feed);
query.setParameter("userId", user.getId());
return query.getSingleResult();
}
public List<FeedEntryWithStatus> getEntries(Feed feed, User user,
boolean unreadOnly) {
return getEntries(feed, user, unreadOnly, -1, -1);

View File

@@ -9,7 +9,7 @@ public class Subscription implements Serializable {
private String name;
private String message;
private String feedUrl;
private int unread;
private long unread;
public Long getId() {
return id;
@@ -27,11 +27,11 @@ public class Subscription implements Serializable {
this.name = name;
}
public int getUnread() {
public long getUnread() {
return unread;
}
public void setUnread(int unread) {
public void setUnread(long unread) {
this.unread = unread;
}

View File

@@ -206,9 +206,8 @@ public class SubscriptionsREST extends AbstractREST {
sub.setName(subscription.getTitle());
sub.setMessage(subscription.getFeed().getMessage());
sub.setFeedUrl(subscription.getFeed().getLink());
// TODO use count instead of retrieving everything here
int size = feedEntryService.getEntries(subscription.getFeed(),
getUser(), true).size();
long size = feedEntryService.getUnreadCount(
subscription.getFeed(), getUser());
sub.setUnread(size);
category.getFeeds().add(sub);
}