mirror of
https://github.com/Athou/commafeed.git
synced 2026-03-21 21:37:29 +00:00
index hashes
This commit is contained in:
@@ -10,6 +10,8 @@ import javax.persistence.criteria.CriteriaQuery;
|
|||||||
import javax.persistence.criteria.Predicate;
|
import javax.persistence.criteria.Predicate;
|
||||||
import javax.persistence.criteria.Root;
|
import javax.persistence.criteria.Root;
|
||||||
|
|
||||||
|
import org.apache.commons.codec.digest.DigestUtils;
|
||||||
|
import org.apache.commons.lang.StringUtils;
|
||||||
import org.apache.commons.lang.time.DateUtils;
|
import org.apache.commons.lang.time.DateUtils;
|
||||||
|
|
||||||
import com.commafeed.backend.model.Feed;
|
import com.commafeed.backend.model.Feed;
|
||||||
@@ -51,8 +53,12 @@ public class FeedDAO extends GenericDAO<Feed> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Feed findByUrl(String url) {
|
public Feed findByUrl(String url) {
|
||||||
List<Feed> feeds = findByField(Feed_.url, url);
|
List<Feed> feeds = findByField(Feed_.urlHash, DigestUtils.sha1Hex(url));
|
||||||
return Iterables.getFirst(feeds, null);
|
Feed feed = Iterables.getFirst(feeds, null);
|
||||||
|
if (feed != null && StringUtils.equals(url, feed.getUrl())) {
|
||||||
|
return feed;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Feed findByIdWithEntries(Long feedId, int offset, int limit) {
|
public Feed findByIdWithEntries(Long feedId, int offset, int limit) {
|
||||||
|
|||||||
@@ -7,9 +7,12 @@ import javax.persistence.TypedQuery;
|
|||||||
import javax.persistence.criteria.CriteriaQuery;
|
import javax.persistence.criteria.CriteriaQuery;
|
||||||
import javax.persistence.criteria.Root;
|
import javax.persistence.criteria.Root;
|
||||||
|
|
||||||
|
import org.apache.commons.codec.digest.DigestUtils;
|
||||||
|
|
||||||
import com.commafeed.backend.model.Feed;
|
import com.commafeed.backend.model.Feed;
|
||||||
import com.commafeed.backend.model.FeedEntry;
|
import com.commafeed.backend.model.FeedEntry;
|
||||||
import com.commafeed.backend.model.FeedEntry_;
|
import com.commafeed.backend.model.FeedEntry_;
|
||||||
|
import com.google.api.client.util.Lists;
|
||||||
import com.uaihebert.model.EasyCriteria;
|
import com.uaihebert.model.EasyCriteria;
|
||||||
|
|
||||||
@Stateless
|
@Stateless
|
||||||
@@ -17,11 +20,23 @@ import com.uaihebert.model.EasyCriteria;
|
|||||||
public class FeedEntryDAO extends GenericDAO<FeedEntry> {
|
public class FeedEntryDAO extends GenericDAO<FeedEntry> {
|
||||||
|
|
||||||
public List<FeedEntry> findByGuids(List<String> guids) {
|
public List<FeedEntry> findByGuids(List<String> guids) {
|
||||||
|
List<String> hashes = Lists.newArrayList();
|
||||||
|
for (String guid : guids) {
|
||||||
|
hashes.add(DigestUtils.sha1Hex(guid));
|
||||||
|
}
|
||||||
|
|
||||||
EasyCriteria<FeedEntry> criteria = createCriteria();
|
EasyCriteria<FeedEntry> criteria = createCriteria();
|
||||||
criteria.setDistinctTrue();
|
criteria.setDistinctTrue();
|
||||||
criteria.andStringIn(FeedEntry_.guid.getName(), guids);
|
criteria.andStringIn(FeedEntry_.guidHash.getName(), hashes);
|
||||||
criteria.leftJoinFetch(FeedEntry_.feeds.getName());
|
criteria.leftJoinFetch(FeedEntry_.feeds.getName());
|
||||||
return criteria.getResultList();
|
|
||||||
|
List<FeedEntry> list = Lists.newArrayList();
|
||||||
|
for (FeedEntry entry : criteria.getResultList()) {
|
||||||
|
if (guids.contains(entry.getGuid())) {
|
||||||
|
list.add(entry);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<FeedEntry> findByFeed(Feed feed, int offset, int limit) {
|
public List<FeedEntry> findByFeed(Feed feed, int offset, int limit) {
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import java.util.Calendar;
|
|||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.apache.commons.codec.digest.DigestUtils;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
import org.apache.commons.lang.SystemUtils;
|
import org.apache.commons.lang.SystemUtils;
|
||||||
import org.jsoup.Jsoup;
|
import org.jsoup.Jsoup;
|
||||||
@@ -49,6 +50,7 @@ public class FeedParser {
|
|||||||
for (SyndEntry item : items) {
|
for (SyndEntry item : items) {
|
||||||
FeedEntry entry = new FeedEntry();
|
FeedEntry entry = new FeedEntry();
|
||||||
entry.setGuid(item.getUri());
|
entry.setGuid(item.getUri());
|
||||||
|
entry.setGuidHash(DigestUtils.sha1Hex(item.getUri()));
|
||||||
entry.setUrl(item.getLink());
|
entry.setUrl(item.getLink());
|
||||||
entry.setUpdated(getUpdateDate(item));
|
entry.setUpdated(getUpdateDate(item));
|
||||||
|
|
||||||
|
|||||||
@@ -21,12 +21,22 @@ import com.google.common.collect.Sets;
|
|||||||
@SuppressWarnings("serial")
|
@SuppressWarnings("serial")
|
||||||
public class Feed extends AbstractModel {
|
public class Feed extends AbstractModel {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The url of the feed
|
||||||
|
*/
|
||||||
@Column(length = 2048, nullable = false)
|
@Column(length = 2048, nullable = false)
|
||||||
private String url;
|
private String url;
|
||||||
|
|
||||||
|
@Column(length = 40, nullable = false)
|
||||||
|
@Index(name = "urlHash_index")
|
||||||
|
private String urlHash;
|
||||||
|
|
||||||
@Transient
|
@Transient
|
||||||
private String title;
|
private String title;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The url of the website, extracted from the feed
|
||||||
|
*/
|
||||||
@Column(length = 2048)
|
@Column(length = 2048)
|
||||||
private String link;
|
private String link;
|
||||||
|
|
||||||
@@ -129,4 +139,12 @@ public class Feed extends AbstractModel {
|
|||||||
this.disabledUntil = disabledUntil;
|
this.disabledUntil = disabledUntil;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getUrlHash() {
|
||||||
|
return urlHash;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUrlHash(String urlHash) {
|
||||||
|
this.urlHash = urlHash;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,6 +28,10 @@ public class FeedEntry extends AbstractModel {
|
|||||||
@Column(length = 2048, nullable = false)
|
@Column(length = 2048, nullable = false)
|
||||||
private String guid;
|
private String guid;
|
||||||
|
|
||||||
|
@Column(length = 40, nullable = false)
|
||||||
|
@Index(name = "guidHash_index")
|
||||||
|
private String guidHash;
|
||||||
|
|
||||||
@ManyToMany
|
@ManyToMany
|
||||||
@JoinTable(name = "FEED_FEEDENTRIES", joinColumns = { @JoinColumn(name = "FEED_ID", nullable = false, updatable = false) }, inverseJoinColumns = { @JoinColumn(name = "FEEDENTRY_ID", nullable = false, updatable = false) })
|
@JoinTable(name = "FEED_FEEDENTRIES", joinColumns = { @JoinColumn(name = "FEED_ID", nullable = false, updatable = false) }, inverseJoinColumns = { @JoinColumn(name = "FEEDENTRY_ID", nullable = false, updatable = false) })
|
||||||
private Set<Feed> feeds = Sets.newHashSet();
|
private Set<Feed> feeds = Sets.newHashSet();
|
||||||
@@ -106,4 +110,12 @@ public class FeedEntry extends AbstractModel {
|
|||||||
this.content = content;
|
this.content = content;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getGuidHash() {
|
||||||
|
return guidHash;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setGuidHash(String guidHash) {
|
||||||
|
this.guidHash = guidHash;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,6 +7,8 @@ import javax.ejb.LockType;
|
|||||||
import javax.ejb.Singleton;
|
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.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;
|
||||||
@@ -42,6 +44,7 @@ public class FeedSubscriptionService {
|
|||||||
if (feed == null) {
|
if (feed == null) {
|
||||||
feed = new Feed();
|
feed = new Feed();
|
||||||
feed.setUrl(url);
|
feed.setUrl(url);
|
||||||
|
feed.setUrlHash(DigestUtils.sha1Hex(url));
|
||||||
feedDAO.save(feed);
|
feedDAO.save(feed);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user