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
|
@Stateless
|
||||||
public class FeedPushInfoDAO extends GenericDAO<FeedPushInfo> {
|
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());
|
CriteriaQuery<FeedPushInfo> query = builder.createQuery(getType());
|
||||||
Root<FeedPushInfo> root = query.from(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));
|
query.where(builder.equal(root.get(FeedPushInfo_.topic), topic));
|
||||||
|
|
||||||
TypedQuery<FeedPushInfo> q = em.createQuery(query);
|
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();
|
FeedPushInfo info = feed.getPushInfo();
|
||||||
if (info != null && info.isActive() == false) {
|
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 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.inject.Inject;
|
||||||
import javax.ws.rs.core.MediaType;
|
import javax.ws.rs.core.MediaType;
|
||||||
|
|
||||||
@@ -25,8 +21,6 @@ import com.commafeed.backend.model.FeedPushInfo;
|
|||||||
import com.commafeed.backend.services.ApplicationSettingsService;
|
import com.commafeed.backend.services.ApplicationSettingsService;
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
|
|
||||||
@Stateless
|
|
||||||
@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
|
|
||||||
public class SubscriptionHandler {
|
public class SubscriptionHandler {
|
||||||
|
|
||||||
private static Logger log = LoggerFactory
|
private static Logger log = LoggerFactory
|
||||||
@@ -35,7 +29,6 @@ public class SubscriptionHandler {
|
|||||||
@Inject
|
@Inject
|
||||||
ApplicationSettingsService applicationSettingsService;
|
ApplicationSettingsService applicationSettingsService;
|
||||||
|
|
||||||
@Asynchronous
|
|
||||||
public void subscribe(Feed feed) {
|
public void subscribe(Feed feed) {
|
||||||
FeedPushInfo info = feed.getPushInfo();
|
FeedPushInfo info = feed.getPushInfo();
|
||||||
String hub = info.getHub();
|
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 = "limit for paging") @DefaultValue("-1") @QueryParam("limit") int limit,
|
||||||
@ApiParam(value = "date ordering", allowableValues = "asc,desc") @QueryParam("order") @DefaultValue("desc") ReadingOrder order) {
|
@ApiParam(value = "date ordering", allowableValues = "asc,desc") @QueryParam("order") @DefaultValue("desc") ReadingOrder order) {
|
||||||
|
|
||||||
Preconditions.checkNotNull(id);
|
|
||||||
Preconditions.checkNotNull(readType);
|
Preconditions.checkNotNull(readType);
|
||||||
|
|
||||||
Entries entries = new Entries();
|
Entries entries = new Entries();
|
||||||
boolean unreadOnly = readType == ReadType.unread;
|
boolean unreadOnly = readType == ReadType.unread;
|
||||||
|
if (StringUtils.isBlank(id)) {
|
||||||
|
id = ALL;
|
||||||
|
}
|
||||||
|
|
||||||
if (ALL.equals(id)) {
|
if (ALL.equals(id)) {
|
||||||
entries.setName("All");
|
entries.setName("All");
|
||||||
@@ -125,7 +127,8 @@ public class CategoryREST extends AbstractResourceREST {
|
|||||||
int offset = 0;
|
int offset = 0;
|
||||||
int limit = 20;
|
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();
|
SyndFeed feed = new SyndFeedImpl();
|
||||||
feed.setFeedType("rss_2.0");
|
feed.setFeedType("rss_2.0");
|
||||||
@@ -294,7 +297,7 @@ public class CategoryREST extends AbstractResourceREST {
|
|||||||
|
|
||||||
@GET
|
@GET
|
||||||
@Path("/unreadCount")
|
@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() {
|
public Response getUnreadCount() {
|
||||||
List<UnreadCount> list = Lists.newArrayList();
|
List<UnreadCount> list = Lists.newArrayList();
|
||||||
Map<Long, Long> unreadCount = feedEntryStatusDAO
|
Map<Long, Long> unreadCount = feedEntryStatusDAO
|
||||||
|
|||||||
@@ -59,12 +59,11 @@ public class PubSubHubbubCallbackREST {
|
|||||||
|
|
||||||
log.info("confirmation callback received for {}", topic);
|
log.info("confirmation callback received for {}", topic);
|
||||||
|
|
||||||
List<FeedPushInfo> infos = feedPushInfoDAO.findByTopic(topic);
|
List<FeedPushInfo> infos = feedPushInfoDAO.findByTopic(topic, false);
|
||||||
|
|
||||||
if (infos.isEmpty() == false) {
|
if (infos.isEmpty() == false) {
|
||||||
for (FeedPushInfo info : infos) {
|
for (FeedPushInfo info : infos) {
|
||||||
log.info("activated push notifications for {}", info.getFeed()
|
log.info("activated push notifications for {}", info.getTopic());
|
||||||
.getUrl());
|
|
||||||
info.setActive(true);
|
info.setActive(true);
|
||||||
}
|
}
|
||||||
feedPushInfoDAO.update(infos);
|
feedPushInfoDAO.update(infos);
|
||||||
@@ -85,7 +84,8 @@ public class PubSubHubbubCallbackREST {
|
|||||||
String topic = fetchedFeed.getTopic();
|
String topic = fetchedFeed.getTopic();
|
||||||
if (topic != null) {
|
if (topic != null) {
|
||||||
log.info("content callback received for {}", topic);
|
log.info("content callback received for {}", topic);
|
||||||
List<FeedPushInfo> infos = feedPushInfoDAO.findByTopic(topic);
|
List<FeedPushInfo> infos = feedPushInfoDAO.findByTopic(topic,
|
||||||
|
true);
|
||||||
for (FeedPushInfo info : infos) {
|
for (FeedPushInfo info : infos) {
|
||||||
Feed feed = info.getFeed();
|
Feed feed = info.getFeed();
|
||||||
log.info("pushing content to queue for {}", feed.getUrl());
|
log.info("pushing content to queue for {}", feed.getUrl());
|
||||||
|
|||||||
Reference in New Issue
Block a user