forked from Archives/Athou_commafeed
move write lock to feed creation only
This commit is contained in:
@@ -0,0 +1,31 @@
|
|||||||
|
package com.commafeed.backend.services;
|
||||||
|
|
||||||
|
import javax.ejb.Lock;
|
||||||
|
import javax.ejb.LockType;
|
||||||
|
import javax.ejb.Singleton;
|
||||||
|
import javax.inject.Inject;
|
||||||
|
|
||||||
|
import org.apache.commons.codec.digest.DigestUtils;
|
||||||
|
|
||||||
|
import com.commafeed.backend.dao.FeedDAO;
|
||||||
|
import com.commafeed.backend.model.Feed;
|
||||||
|
|
||||||
|
@Singleton
|
||||||
|
public class FeedService {
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
FeedDAO feedDAO;
|
||||||
|
|
||||||
|
@Lock(LockType.WRITE)
|
||||||
|
public Feed findOrCreate(String url) {
|
||||||
|
Feed feed = feedDAO.findByUrl(url);
|
||||||
|
if (feed == null) {
|
||||||
|
feed = new Feed();
|
||||||
|
feed.setUrl(url);
|
||||||
|
feed.setUrlHash(DigestUtils.sha1Hex(url));
|
||||||
|
feedDAO.save(feed);
|
||||||
|
}
|
||||||
|
return feed;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -2,14 +2,9 @@ package com.commafeed.backend.services;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import javax.ejb.Lock;
|
import javax.ejb.Stateless;
|
||||||
import javax.ejb.LockType;
|
|
||||||
import javax.ejb.Singleton;
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
import org.apache.commons.codec.digest.DigestUtils;
|
|
||||||
|
|
||||||
import com.commafeed.backend.dao.FeedDAO;
|
|
||||||
import com.commafeed.backend.dao.FeedEntryDAO;
|
import com.commafeed.backend.dao.FeedEntryDAO;
|
||||||
import com.commafeed.backend.dao.FeedEntryStatusDAO;
|
import com.commafeed.backend.dao.FeedEntryStatusDAO;
|
||||||
import com.commafeed.backend.dao.FeedSubscriptionDAO;
|
import com.commafeed.backend.dao.FeedSubscriptionDAO;
|
||||||
@@ -21,11 +16,11 @@ import com.commafeed.backend.model.FeedSubscription;
|
|||||||
import com.commafeed.backend.model.User;
|
import com.commafeed.backend.model.User;
|
||||||
import com.google.api.client.util.Lists;
|
import com.google.api.client.util.Lists;
|
||||||
|
|
||||||
@Singleton
|
@Stateless
|
||||||
public class FeedSubscriptionService {
|
public class FeedSubscriptionService {
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
FeedDAO feedDAO;
|
FeedService feedService;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
FeedEntryDAO feedEntryDAO;
|
FeedEntryDAO feedEntryDAO;
|
||||||
@@ -36,17 +31,10 @@ public class FeedSubscriptionService {
|
|||||||
@Inject
|
@Inject
|
||||||
FeedSubscriptionDAO feedSubscriptionDAO;
|
FeedSubscriptionDAO feedSubscriptionDAO;
|
||||||
|
|
||||||
@Lock(LockType.WRITE)
|
|
||||||
public Feed subscribe(User user, String url, String title,
|
public Feed subscribe(User user, String url, String title,
|
||||||
FeedCategory category) {
|
FeedCategory category) {
|
||||||
|
|
||||||
Feed feed = feedDAO.findByUrl(url);
|
Feed feed = feedService.findOrCreate(url);
|
||||||
if (feed == null) {
|
|
||||||
feed = new Feed();
|
|
||||||
feed.setUrl(url);
|
|
||||||
feed.setUrlHash(DigestUtils.sha1Hex(url));
|
|
||||||
feedDAO.save(feed);
|
|
||||||
}
|
|
||||||
|
|
||||||
FeedSubscription sub = feedSubscriptionDAO.findByFeed(user, feed);
|
FeedSubscription sub = feedSubscriptionDAO.findByFeed(user, feed);
|
||||||
boolean newSubscription = false;
|
boolean newSubscription = false;
|
||||||
|
|||||||
Reference in New Issue
Block a user