mirror of
https://github.com/Athou/commafeed.git
synced 2026-03-21 21:37:29 +00:00
return count only (fixes #18)
This commit is contained in:
@@ -112,6 +112,14 @@ public class FeedEntryService extends GenericDAO<FeedEntry> {
|
|||||||
return buildList(query.getResultList());
|
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,
|
public List<FeedEntryWithStatus> getEntries(Feed feed, User user,
|
||||||
boolean unreadOnly) {
|
boolean unreadOnly) {
|
||||||
return getEntries(feed, user, unreadOnly, -1, -1);
|
return getEntries(feed, user, unreadOnly, -1, -1);
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ public class Subscription implements Serializable {
|
|||||||
private String name;
|
private String name;
|
||||||
private String message;
|
private String message;
|
||||||
private String feedUrl;
|
private String feedUrl;
|
||||||
private int unread;
|
private long unread;
|
||||||
|
|
||||||
public Long getId() {
|
public Long getId() {
|
||||||
return id;
|
return id;
|
||||||
@@ -27,11 +27,11 @@ public class Subscription implements Serializable {
|
|||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getUnread() {
|
public long getUnread() {
|
||||||
return unread;
|
return unread;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setUnread(int unread) {
|
public void setUnread(long unread) {
|
||||||
this.unread = unread;
|
this.unread = unread;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -206,9 +206,8 @@ public class SubscriptionsREST extends AbstractREST {
|
|||||||
sub.setName(subscription.getTitle());
|
sub.setName(subscription.getTitle());
|
||||||
sub.setMessage(subscription.getFeed().getMessage());
|
sub.setMessage(subscription.getFeed().getMessage());
|
||||||
sub.setFeedUrl(subscription.getFeed().getLink());
|
sub.setFeedUrl(subscription.getFeed().getLink());
|
||||||
// TODO use count instead of retrieving everything here
|
long size = feedEntryService.getUnreadCount(
|
||||||
int size = feedEntryService.getEntries(subscription.getFeed(),
|
subscription.getFeed(), getUser());
|
||||||
getUser(), true).size();
|
|
||||||
sub.setUnread(size);
|
sub.setUnread(size);
|
||||||
category.getFeeds().add(sub);
|
category.getFeeds().add(sub);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,6 +23,9 @@
|
|||||||
<named-query name="Entry.unreadByFeed">
|
<named-query name="Entry.unreadByFeed">
|
||||||
<query>select e, s from FeedEntry e LEFT JOIN e.statuses s WITH (s.user.id=:userId) where e.feed=:feed and not exists (select s2 from FeedEntryStatus s2 where s2.entry=e and s2.user.id=:userId and s2.read=true) order by e.updated desc</query>
|
<query>select e, s from FeedEntry e LEFT JOIN e.statuses s WITH (s.user.id=:userId) where e.feed=:feed and not exists (select s2 from FeedEntryStatus s2 where s2.entry=e and s2.user.id=:userId and s2.read=true) order by e.updated desc</query>
|
||||||
</named-query>
|
</named-query>
|
||||||
|
<named-query name="Entry.unreadByFeedCount">
|
||||||
|
<query>select count(e) from FeedEntry e LEFT JOIN e.statuses s WITH (s.user.id=:userId) where e.feed=:feed and not exists (select s2 from FeedEntryStatus s2 where s2.entry=e and s2.user.id=:userId and s2.read=true)</query>
|
||||||
|
</named-query>
|
||||||
<named-query name="Entry.allByFeed">
|
<named-query name="Entry.allByFeed">
|
||||||
<query>select e, s from FeedEntry e LEFT JOIN e.statuses s WITH (s.user.id=:userId) where e.feed=:feed order by e.updated desc</query>
|
<query>select e, s from FeedEntry e LEFT JOIN e.statuses s WITH (s.user.id=:userId) where e.feed=:feed order by e.updated desc</query>
|
||||||
</named-query>
|
</named-query>
|
||||||
|
|||||||
Reference in New Issue
Block a user