mirror of
https://github.com/Athou/commafeed.git
synced 2026-03-21 21:37:29 +00:00
small optimizations
This commit is contained in:
@@ -13,11 +13,13 @@ import com.commafeed.backend.model.FeedPushInfo_;
|
||||
@Stateless
|
||||
public class FeedPushInfoDAO extends GenericDAO<FeedPushInfo> {
|
||||
|
||||
public List<FeedPushInfo> findByTopic(String topic) {
|
||||
public List<FeedPushInfo> findByTopic(String topic, boolean includeFeed) {
|
||||
|
||||
CriteriaQuery<FeedPushInfo> query = builder.createQuery(getType());
|
||||
Root<FeedPushInfo> root = query.from(getType());
|
||||
root.fetch(FeedPushInfo_.feed);
|
||||
if (includeFeed) {
|
||||
root.fetch(FeedPushInfo_.feed);
|
||||
}
|
||||
query.where(builder.equal(root.get(FeedPushInfo_.topic), topic));
|
||||
|
||||
TypedQuery<FeedPushInfo> q = em.createQuery(query);
|
||||
|
||||
@@ -47,10 +47,15 @@ public class FeedRefreshUpdater {
|
||||
}
|
||||
}
|
||||
|
||||
private void handlePubSub(Feed feed) {
|
||||
private void handlePubSub(final Feed feed) {
|
||||
FeedPushInfo info = feed.getPushInfo();
|
||||
if (info != null && info.isActive() == false) {
|
||||
handler.subscribe(feed);
|
||||
new Thread() {
|
||||
@Override
|
||||
public void run() {
|
||||
handler.subscribe(feed);
|
||||
}
|
||||
}.start();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,10 +2,6 @@ package com.commafeed.backend.pubsubhubbub;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.ejb.Asynchronous;
|
||||
import javax.ejb.Stateless;
|
||||
import javax.ejb.TransactionAttribute;
|
||||
import javax.ejb.TransactionAttributeType;
|
||||
import javax.inject.Inject;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
|
||||
@@ -25,8 +21,6 @@ import com.commafeed.backend.model.FeedPushInfo;
|
||||
import com.commafeed.backend.services.ApplicationSettingsService;
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
@Stateless
|
||||
@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
|
||||
public class SubscriptionHandler {
|
||||
|
||||
private static Logger log = LoggerFactory
|
||||
@@ -35,7 +29,6 @@ public class SubscriptionHandler {
|
||||
@Inject
|
||||
ApplicationSettingsService applicationSettingsService;
|
||||
|
||||
@Asynchronous
|
||||
public void subscribe(Feed feed) {
|
||||
FeedPushInfo info = feed.getPushInfo();
|
||||
String hub = info.getHub();
|
||||
|
||||
@@ -69,11 +69,13 @@ public class CategoryREST extends AbstractResourceREST {
|
||||
@ApiParam(value = "limit for paging") @DefaultValue("-1") @QueryParam("limit") int limit,
|
||||
@ApiParam(value = "date ordering", allowableValues = "asc,desc") @QueryParam("order") @DefaultValue("desc") ReadingOrder order) {
|
||||
|
||||
Preconditions.checkNotNull(id);
|
||||
Preconditions.checkNotNull(readType);
|
||||
|
||||
Entries entries = new Entries();
|
||||
boolean unreadOnly = readType == ReadType.unread;
|
||||
if (StringUtils.isBlank(id)) {
|
||||
id = ALL;
|
||||
}
|
||||
|
||||
if (ALL.equals(id)) {
|
||||
entries.setName("All");
|
||||
@@ -125,7 +127,8 @@ public class CategoryREST extends AbstractResourceREST {
|
||||
int offset = 0;
|
||||
int limit = 20;
|
||||
|
||||
Entries entries = (Entries) getCategoryEntries(id, readType, offset, limit, order).getEntity();
|
||||
Entries entries = (Entries) getCategoryEntries(id, readType, offset,
|
||||
limit, order).getEntity();
|
||||
|
||||
SyndFeed feed = new SyndFeedImpl();
|
||||
feed.setFeedType("rss_2.0");
|
||||
@@ -294,7 +297,7 @@ public class CategoryREST extends AbstractResourceREST {
|
||||
|
||||
@GET
|
||||
@Path("/unreadCount")
|
||||
@ApiOperation(value = "Get unread count for feed subscriptions", responseClass="List[com.commafeed.frontend.model.UnreadCount]")
|
||||
@ApiOperation(value = "Get unread count for feed subscriptions", responseClass = "List[com.commafeed.frontend.model.UnreadCount]")
|
||||
public Response getUnreadCount() {
|
||||
List<UnreadCount> list = Lists.newArrayList();
|
||||
Map<Long, Long> unreadCount = feedEntryStatusDAO
|
||||
|
||||
@@ -59,12 +59,11 @@ public class PubSubHubbubCallbackREST {
|
||||
|
||||
log.info("confirmation callback received for {}", topic);
|
||||
|
||||
List<FeedPushInfo> infos = feedPushInfoDAO.findByTopic(topic);
|
||||
List<FeedPushInfo> infos = feedPushInfoDAO.findByTopic(topic, false);
|
||||
|
||||
if (infos.isEmpty() == false) {
|
||||
for (FeedPushInfo info : infos) {
|
||||
log.info("activated push notifications for {}", info.getFeed()
|
||||
.getUrl());
|
||||
log.info("activated push notifications for {}", info.getTopic());
|
||||
info.setActive(true);
|
||||
}
|
||||
feedPushInfoDAO.update(infos);
|
||||
@@ -85,7 +84,8 @@ public class PubSubHubbubCallbackREST {
|
||||
String topic = fetchedFeed.getTopic();
|
||||
if (topic != null) {
|
||||
log.info("content callback received for {}", topic);
|
||||
List<FeedPushInfo> infos = feedPushInfoDAO.findByTopic(topic);
|
||||
List<FeedPushInfo> infos = feedPushInfoDAO.findByTopic(topic,
|
||||
true);
|
||||
for (FeedPushInfo info : infos) {
|
||||
Feed feed = info.getFeed();
|
||||
log.info("pushing content to queue for {}", feed.getUrl());
|
||||
|
||||
Reference in New Issue
Block a user