mirror of
https://github.com/Athou/commafeed.git
synced 2026-03-21 21:37:29 +00:00
store only 10 entries for new users
This commit is contained in:
@@ -7,6 +7,9 @@ import java.util.List;
|
|||||||
|
|
||||||
import javax.ejb.Stateless;
|
import javax.ejb.Stateless;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
import javax.persistence.TypedQuery;
|
||||||
|
import javax.persistence.criteria.CriteriaQuery;
|
||||||
|
import javax.persistence.criteria.Root;
|
||||||
|
|
||||||
import org.apache.commons.lang.ObjectUtils;
|
import org.apache.commons.lang.ObjectUtils;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
@@ -14,6 +17,7 @@ import org.apache.commons.lang.StringUtils;
|
|||||||
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.FeedEntryStatus;
|
import com.commafeed.backend.model.FeedEntryStatus;
|
||||||
|
import com.commafeed.backend.model.FeedEntry_;
|
||||||
import com.commafeed.backend.model.FeedSubscription;
|
import com.commafeed.backend.model.FeedSubscription;
|
||||||
import com.commafeed.frontend.utils.ModelFactory.MF;
|
import com.commafeed.frontend.utils.ModelFactory.MF;
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
@@ -37,7 +41,7 @@ public class FeedEntryService extends GenericDAO<FeedEntry> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
List<FeedEntry> existingEntries = guids.isEmpty() ? new ArrayList<FeedEntry>()
|
List<FeedEntry> existingEntries = guids.isEmpty() ? new ArrayList<FeedEntry>()
|
||||||
: getByGuids(guids);
|
: findByGuids(guids);
|
||||||
for (FeedEntry entry : entries) {
|
for (FeedEntry entry : entries) {
|
||||||
FeedEntry foundEntry = null;
|
FeedEntry foundEntry = null;
|
||||||
for (FeedEntry existingEntry : existingEntries) {
|
for (FeedEntry existingEntry : existingEntries) {
|
||||||
@@ -80,7 +84,7 @@ public class FeedEntryService extends GenericDAO<FeedEntry> {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<FeedEntry> getByGuids(List<String> guids) {
|
public List<FeedEntry> findByGuids(List<String> guids) {
|
||||||
EasyCriteria<FeedEntry> criteria = createCriteria();
|
EasyCriteria<FeedEntry> criteria = createCriteria();
|
||||||
criteria.setDistinctTrue();
|
criteria.setDistinctTrue();
|
||||||
criteria.andStringIn(MF.i(proxy().getGuid()), guids);
|
criteria.andStringIn(MF.i(proxy().getGuid()), guids);
|
||||||
@@ -88,4 +92,14 @@ public class FeedEntryService extends GenericDAO<FeedEntry> {
|
|||||||
return criteria.getResultList();
|
return criteria.getResultList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<FeedEntry> findByFeed(Feed feed, int offset, int limit) {
|
||||||
|
CriteriaQuery<FeedEntry> query = builder.createQuery(getType());
|
||||||
|
Root<FeedEntry> root = query.from(getType());
|
||||||
|
query.where(builder.isMember(feed, root.get(FeedEntry_.feeds)));
|
||||||
|
query.orderBy(builder.desc(root.get(FeedEntry_.updated)));
|
||||||
|
TypedQuery<FeedEntry> q = em.createQuery(query);
|
||||||
|
q.setFirstResult(offset);
|
||||||
|
q.setMaxResults(limit);
|
||||||
|
return q.getResultList();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,10 +25,13 @@ public class FeedService extends GenericDAO<Feed> {
|
|||||||
return Iterables.getFirst(feeds, null);
|
return Iterables.getFirst(feeds, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Feed getByIdWithEntries(Long feedId) {
|
public Feed getByIdWithEntries(Long feedId, int offset, int limit) {
|
||||||
EasyCriteria<Feed> criteria = createCriteria();
|
EasyCriteria<Feed> criteria = createCriteria();
|
||||||
criteria.andEquals(MF.i(proxy().getId()), feedId);
|
criteria.andEquals(MF.i(proxy().getId()), feedId);
|
||||||
criteria.leftJoinFetch(MF.i(proxy().getEntries()));
|
criteria.leftJoinFetch(MF.i(proxy().getEntries()));
|
||||||
|
|
||||||
|
criteria.setFirstResult(offset);
|
||||||
|
criteria.setMaxResults(limit);
|
||||||
return criteria.getSingleResult();
|
return criteria.getSingleResult();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package com.commafeed.backend.dao;
|
package com.commafeed.backend.dao;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import javax.ejb.Stateless;
|
import javax.ejb.Stateless;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
@@ -28,6 +27,9 @@ public class FeedSubscriptionService extends GenericDAO<FeedSubscription> {
|
|||||||
@Inject
|
@Inject
|
||||||
FeedService feedService;
|
FeedService feedService;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
FeedEntryService feedEntryService;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
FeedEntryStatusService feedEntryStatusService;
|
FeedEntryStatusService feedEntryStatusService;
|
||||||
|
|
||||||
@@ -42,26 +44,30 @@ public class FeedSubscriptionService extends GenericDAO<FeedSubscription> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
FeedSubscription sub = findByFeed(user, feed);
|
FeedSubscription sub = findByFeed(user, feed);
|
||||||
|
boolean newSubscription = false;
|
||||||
if (sub == null) {
|
if (sub == null) {
|
||||||
sub = new FeedSubscription();
|
sub = new FeedSubscription();
|
||||||
sub.setFeed(feed);
|
sub.setFeed(feed);
|
||||||
sub.setUser(user);
|
sub.setUser(user);
|
||||||
|
newSubscription = true;
|
||||||
}
|
}
|
||||||
sub.setCategory(category);
|
sub.setCategory(category);
|
||||||
sub.setTitle(title);
|
sub.setTitle(title);
|
||||||
saveOrUpdate(sub);
|
saveOrUpdate(sub);
|
||||||
|
|
||||||
List<FeedEntryStatus> statuses = Lists.newArrayList();
|
if (newSubscription) {
|
||||||
Set<FeedEntry> allEntries = feedService
|
List<FeedEntryStatus> statuses = Lists.newArrayList();
|
||||||
.getByIdWithEntries(feed.getId()).getEntries();
|
List<FeedEntry> allEntries = feedEntryService.findByFeed(feed, 0,
|
||||||
for (FeedEntry entry : allEntries) {
|
10);
|
||||||
FeedEntryStatus status = new FeedEntryStatus();
|
for (FeedEntry entry : allEntries) {
|
||||||
status.setEntry(entry);
|
FeedEntryStatus status = new FeedEntryStatus();
|
||||||
status.setRead(true);
|
status.setEntry(entry);
|
||||||
status.setSubscription(sub);
|
status.setRead(true);
|
||||||
statuses.add(status);
|
status.setSubscription(sub);
|
||||||
|
statuses.add(status);
|
||||||
|
}
|
||||||
|
feedEntryStatusService.save(statuses);
|
||||||
}
|
}
|
||||||
feedEntryStatusService.save(statuses);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public FeedSubscription findById(User user, Long id) {
|
public FeedSubscription findById(User user, Long id) {
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package com.commafeed.frontend.pages;
|
|||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
|
||||||
|
import org.apache.wicket.RestartResponseException;
|
||||||
import org.apache.wicket.markup.html.WebPage;
|
import org.apache.wicket.markup.html.WebPage;
|
||||||
import org.apache.wicket.request.Url;
|
import org.apache.wicket.request.Url;
|
||||||
import org.apache.wicket.request.UrlRenderer;
|
import org.apache.wicket.request.UrlRenderer;
|
||||||
@@ -59,7 +60,8 @@ public class GoogleImportCallbackPage extends WebPage {
|
|||||||
String code = responseUrl.getCode();
|
String code = responseUrl.getCode();
|
||||||
|
|
||||||
if (responseUrl.getError() != null) {
|
if (responseUrl.getError() != null) {
|
||||||
throw new DisplayException(responseUrl.getError());
|
// user declined
|
||||||
|
throw new RestartResponseException(getApplication().getHomePage());
|
||||||
} else if (code == null) {
|
} else if (code == null) {
|
||||||
throw new DisplayException("Missing authorization code");
|
throw new DisplayException("Missing authorization code");
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ public class GoogleImportRedirectPage extends WebPage {
|
|||||||
builder.addParameter("redirect_uri", redirectUri);
|
builder.addParameter("redirect_uri", redirectUri);
|
||||||
builder.addParameter("response_type", "code");
|
builder.addParameter("response_type", "code");
|
||||||
builder.addParameter("scope", SCOPE);
|
builder.addParameter("scope", SCOPE);
|
||||||
builder.addParameter("approval_prompt", "auto");
|
builder.addParameter("approval_prompt", "force");
|
||||||
builder.addParameter("client_id", clientId);
|
builder.addParameter("client_id", clientId);
|
||||||
builder.addParameter("state",
|
builder.addParameter("state",
|
||||||
String.valueOf(CommaFeedSession.get().getUser().getId()));
|
String.valueOf(CommaFeedSession.get().getUser().getId()));
|
||||||
|
|||||||
Reference in New Issue
Block a user