mirror of
https://github.com/Athou/commafeed.git
synced 2026-03-21 21:37:29 +00:00
delete old statuses
This commit is contained in:
@@ -14,10 +14,11 @@ import javax.persistence.criteria.Path;
|
||||
import javax.persistence.criteria.Predicate;
|
||||
import javax.persistence.criteria.Root;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
import org.apache.commons.lang3.time.DateUtils;
|
||||
import org.hibernate.Criteria;
|
||||
import org.hibernate.criterion.Disjunction;
|
||||
import org.hibernate.criterion.MatchMode;
|
||||
import org.hibernate.criterion.Order;
|
||||
import org.hibernate.criterion.ProjectionList;
|
||||
import org.hibernate.criterion.Projections;
|
||||
@@ -80,8 +81,14 @@ public class FeedEntryStatusDAO extends GenericDAO<FeedEntryStatus> {
|
||||
List<FeedEntryStatus> statuses = em.createQuery(query).getResultList();
|
||||
FeedEntryStatus status = Iterables.getFirst(statuses, null);
|
||||
if (status == null) {
|
||||
Date unreadThreshold = getUnreadThreshold();
|
||||
boolean read = unreadThreshold == null ? false : entry
|
||||
.getInserted().before(unreadThreshold);
|
||||
status = new FeedEntryStatus(sub.getUser(), sub, entry);
|
||||
status.setRead(false);
|
||||
status.setRead(read);
|
||||
status.setMarkable(!read);
|
||||
} else {
|
||||
status.setMarkable(true);
|
||||
}
|
||||
return status;
|
||||
}
|
||||
@@ -134,30 +141,33 @@ public class FeedEntryStatusDAO extends GenericDAO<FeedEntryStatus> {
|
||||
FeedEntry_.content.getName(), "content",
|
||||
JoinType.INNER_JOIN);
|
||||
|
||||
String joinedKeywords = StringUtils.join(keywords.toLowerCase()
|
||||
.split(" "), "%");
|
||||
joinedKeywords = "%" + joinedKeywords + "%";
|
||||
|
||||
Disjunction or = Restrictions.disjunction();
|
||||
or.add(Restrictions.ilike(FeedEntryContent_.content.getName(),
|
||||
joinedKeywords));
|
||||
or.add(Restrictions.ilike(FeedEntryContent_.title.getName(),
|
||||
joinedKeywords));
|
||||
contentJoin.add(or);
|
||||
for (String keyword : keywords.split(" ")) {
|
||||
Disjunction or = Restrictions.disjunction();
|
||||
or.add(Restrictions.ilike(FeedEntryContent_.content.getName(),
|
||||
keyword, MatchMode.ANYWHERE));
|
||||
or.add(Restrictions.ilike(FeedEntryContent_.title.getName(),
|
||||
keyword, MatchMode.ANYWHERE));
|
||||
contentJoin.add(or);
|
||||
}
|
||||
}
|
||||
|
||||
if (unreadOnly) {
|
||||
|
||||
Criteria statusJoin = criteria.createCriteria(FeedEntry_.statuses
|
||||
.getName(), "status", JoinType.LEFT_OUTER_JOIN,
|
||||
Restrictions.eq(FeedEntryStatus_.subscription.getName(),
|
||||
sub));
|
||||
|
||||
Disjunction or = Restrictions.disjunction();
|
||||
or.add(Restrictions.isNull(FeedEntryStatus_.id.getName()));
|
||||
or.add(Restrictions.isNull(FeedEntryStatus_.read.getName()));
|
||||
or.add(Restrictions.eq(FeedEntryStatus_.read.getName(), false));
|
||||
|
||||
statusJoin.add(or);
|
||||
|
||||
Date unreadThreshold = getUnreadThreshold();
|
||||
if (unreadThreshold != null) {
|
||||
criteria.add(Restrictions.ge(FeedEntry_.inserted.getName(),
|
||||
unreadThreshold));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (last != null) {
|
||||
@@ -175,11 +185,11 @@ public class FeedEntryStatusDAO extends GenericDAO<FeedEntryStatus> {
|
||||
if (order != null) {
|
||||
Order o = null;
|
||||
if (order == ReadingOrder.asc) {
|
||||
o = Order.asc(FeedEntry_.updated.getName());
|
||||
o = Order.asc(FeedFeedEntry_.entryUpdated.getName());
|
||||
} else {
|
||||
o = Order.desc(FeedEntry_.updated.getName());
|
||||
o = Order.desc(FeedFeedEntry_.entryUpdated.getName());
|
||||
}
|
||||
criteria.addOrder(o);
|
||||
ffeJoin.addOrder(o);
|
||||
}
|
||||
if (offset > -1) {
|
||||
criteria.setFirstResult(offset);
|
||||
@@ -235,6 +245,13 @@ public class FeedEntryStatusDAO extends GenericDAO<FeedEntryStatus> {
|
||||
return lazyLoadContent(includeContent, results);
|
||||
}
|
||||
|
||||
private Date getUnreadThreshold() {
|
||||
int keepStatusDays = applicationSettingsService.get()
|
||||
.getKeepStatusDays();
|
||||
return keepStatusDays > 0 ? DateUtils.addMinutes(new Date(), -1
|
||||
* keepStatusDays) : null;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public Long getUnreadCount(FeedSubscription subscription) {
|
||||
Long count = null;
|
||||
|
||||
@@ -35,6 +35,7 @@ public class ApplicationSettings extends AbstractModel {
|
||||
private boolean imageProxyEnabled;
|
||||
private int queryTimeout;
|
||||
private boolean crawlingPaused;
|
||||
private int keepStatusDays = 0;
|
||||
|
||||
@Column(length = 255)
|
||||
private String announcement;
|
||||
@@ -200,4 +201,12 @@ public class ApplicationSettings extends AbstractModel {
|
||||
this.crawlingPaused = crawlingPaused;
|
||||
}
|
||||
|
||||
public int getKeepStatusDays() {
|
||||
return keepStatusDays;
|
||||
}
|
||||
|
||||
public void setKeepStatusDays(int keepStatusDays) {
|
||||
this.keepStatusDays = keepStatusDays;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ import javax.persistence.ManyToOne;
|
||||
import javax.persistence.Table;
|
||||
import javax.persistence.Temporal;
|
||||
import javax.persistence.TemporalType;
|
||||
import javax.persistence.Transient;
|
||||
|
||||
import org.hibernate.annotations.Cache;
|
||||
import org.hibernate.annotations.CacheConcurrencyStrategy;
|
||||
@@ -34,6 +35,9 @@ public class FeedEntryStatus extends AbstractModel {
|
||||
private boolean read;
|
||||
private boolean starred;
|
||||
|
||||
@Transient
|
||||
private boolean markable;
|
||||
|
||||
/**
|
||||
* Denormalization starts here
|
||||
*/
|
||||
@@ -52,7 +56,8 @@ public class FeedEntryStatus extends AbstractModel {
|
||||
|
||||
}
|
||||
|
||||
public FeedEntryStatus(User user, FeedSubscription subscription, FeedEntry entry) {
|
||||
public FeedEntryStatus(User user, FeedSubscription subscription,
|
||||
FeedEntry entry) {
|
||||
setUser(user);
|
||||
setSubscription(subscription);
|
||||
setEntry(entry);
|
||||
@@ -116,4 +121,12 @@ public class FeedEntryStatus extends AbstractModel {
|
||||
this.user = user;
|
||||
}
|
||||
|
||||
public boolean isMarkable() {
|
||||
return markable;
|
||||
}
|
||||
|
||||
public void setMarkable(boolean markable) {
|
||||
this.markable = markable;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
package com.commafeed.backend.services;
|
||||
|
||||
import javax.ejb.Stateless;
|
||||
import javax.inject.Inject;
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.PersistenceContext;
|
||||
import javax.persistence.Query;
|
||||
|
||||
@Stateless
|
||||
public class CleaningService {
|
||||
|
||||
@Inject
|
||||
ApplicationSettingsService applicationSettingsService;
|
||||
|
||||
@PersistenceContext
|
||||
EntityManager em;
|
||||
|
||||
// @Schedule(hour = "*")
|
||||
protected void cleanOldStatuses() {
|
||||
int keepStatusDays = applicationSettingsService.get()
|
||||
.getKeepStatusDays();
|
||||
if (keepStatusDays > 0) {
|
||||
Query query = em.createNamedQuery("Statuses.deleteOld");
|
||||
query.executeUpdate();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -33,6 +33,7 @@ public class Entry implements Serializable {
|
||||
|
||||
entry.setRead(status.isRead());
|
||||
entry.setStarred(status.isStarred());
|
||||
entry.setMarkable(status.isMarkable());
|
||||
|
||||
entry.setId(String.valueOf(feedEntry.getId()));
|
||||
entry.setGuid(feedEntry.getGuid());
|
||||
@@ -124,6 +125,9 @@ public class Entry implements Serializable {
|
||||
@ApiProperty("starred status")
|
||||
private boolean starred;
|
||||
|
||||
@ApiProperty("wether the entry is still markable (old entry statuses are discarded)")
|
||||
private boolean markable;
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
@@ -268,4 +272,12 @@ public class Entry implements Serializable {
|
||||
this.insertedDate = insertedDate;
|
||||
}
|
||||
|
||||
public boolean isMarkable() {
|
||||
return markable;
|
||||
}
|
||||
|
||||
public void setMarkable(boolean markable) {
|
||||
this.markable = markable;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user