mirror of
https://github.com/Athou/commafeed.git
synced 2026-03-21 21:37:29 +00:00
make eclipse mars happy
This commit is contained in:
@@ -18,13 +18,13 @@ public class UnitOfWork {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void run(SessionFactory sessionFactory, SessionRunner sessionRunner) {
|
public static void run(SessionFactory sessionFactory, SessionRunner sessionRunner) {
|
||||||
run(sessionFactory, () -> {
|
call(sessionFactory, () -> {
|
||||||
sessionRunner.runInSession();
|
sessionRunner.runInSession();
|
||||||
return null;
|
return null;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <T> T run(SessionFactory sessionFactory, SessionRunnerReturningValue<T> sessionRunner) {
|
public static <T> T call(SessionFactory sessionFactory, SessionRunnerReturningValue<T> sessionRunner) {
|
||||||
final Session session = sessionFactory.openSession();
|
final Session session = sessionFactory.openSession();
|
||||||
if (ManagedSessionContext.hasBind(sessionFactory)) {
|
if (ManagedSessionContext.hasBind(sessionFactory)) {
|
||||||
throw new IllegalStateException("Already in a unit of work!");
|
throw new IllegalStateException("Already in a unit of work!");
|
||||||
|
|||||||
@@ -108,7 +108,7 @@ public class FeedQueues {
|
|||||||
// add feeds that are up to refresh from the database
|
// add feeds that are up to refresh from the database
|
||||||
int count = batchSize - contexts.size();
|
int count = batchSize - contexts.size();
|
||||||
if (count > 0) {
|
if (count > 0) {
|
||||||
List<Feed> feeds = UnitOfWork.run(sessionFactory, () -> feedDAO.findNextUpdatable(count, getLastLoginThreshold()));
|
List<Feed> feeds = UnitOfWork.call(sessionFactory, () -> feedDAO.findNextUpdatable(count, getLastLoginThreshold()));
|
||||||
for (Feed feed : feeds) {
|
for (Feed feed : feeds) {
|
||||||
contexts.add(new FeedRefreshContext(feed, false));
|
contexts.add(new FeedRefreshContext(feed, false));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
package com.commafeed.backend.feed;
|
package com.commafeed.backend.feed;
|
||||||
|
|
||||||
import io.dropwizard.lifecycle.Managed;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
@@ -14,8 +12,6 @@ import java.util.stream.Collectors;
|
|||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
|
|
||||||
import org.apache.commons.codec.digest.DigestUtils;
|
import org.apache.commons.codec.digest.DigestUtils;
|
||||||
import org.apache.commons.collections4.CollectionUtils;
|
import org.apache.commons.collections4.CollectionUtils;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
@@ -39,6 +35,9 @@ import com.commafeed.backend.service.FeedUpdateService;
|
|||||||
import com.commafeed.backend.service.PubSubService;
|
import com.commafeed.backend.service.PubSubService;
|
||||||
import com.google.common.util.concurrent.Striped;
|
import com.google.common.util.concurrent.Striped;
|
||||||
|
|
||||||
|
import io.dropwizard.lifecycle.Managed;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@Singleton
|
@Singleton
|
||||||
public class FeedRefreshUpdater implements Managed {
|
public class FeedRefreshUpdater implements Managed {
|
||||||
@@ -121,7 +120,7 @@ public class FeedRefreshUpdater implements Managed {
|
|||||||
if (!lastEntries.contains(cacheKey)) {
|
if (!lastEntries.contains(cacheKey)) {
|
||||||
log.debug("cache miss for {}", entry.getUrl());
|
log.debug("cache miss for {}", entry.getUrl());
|
||||||
if (subscriptions == null) {
|
if (subscriptions == null) {
|
||||||
subscriptions = UnitOfWork.run(sessionFactory, () -> feedSubscriptionDAO.findByFeed(feed));
|
subscriptions = UnitOfWork.call(sessionFactory, () -> feedSubscriptionDAO.findByFeed(feed));
|
||||||
}
|
}
|
||||||
ok &= addEntry(feed, entry, subscriptions);
|
ok &= addEntry(feed, entry, subscriptions);
|
||||||
entryCacheMiss.mark();
|
entryCacheMiss.mark();
|
||||||
@@ -183,7 +182,7 @@ public class FeedRefreshUpdater implements Managed {
|
|||||||
locked1 = lock1.tryLock(1, TimeUnit.MINUTES);
|
locked1 = lock1.tryLock(1, TimeUnit.MINUTES);
|
||||||
locked2 = lock2.tryLock(1, TimeUnit.MINUTES);
|
locked2 = lock2.tryLock(1, TimeUnit.MINUTES);
|
||||||
if (locked1 && locked2) {
|
if (locked1 && locked2) {
|
||||||
boolean inserted = UnitOfWork.run(sessionFactory, () -> feedUpdateService.addEntry(feed, entry, subscriptions));
|
boolean inserted = UnitOfWork.call(sessionFactory, () -> feedUpdateService.addEntry(feed, entry, subscriptions));
|
||||||
if (inserted) {
|
if (inserted) {
|
||||||
entryInserted.mark();
|
entryInserted.mark();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,9 +6,6 @@ import java.util.List;
|
|||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
import lombok.RequiredArgsConstructor;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
|
|
||||||
import org.hibernate.SessionFactory;
|
import org.hibernate.SessionFactory;
|
||||||
|
|
||||||
import com.commafeed.backend.dao.FeedDAO;
|
import com.commafeed.backend.dao.FeedDAO;
|
||||||
@@ -19,12 +16,15 @@ import com.commafeed.backend.dao.FeedEntryStatusDAO;
|
|||||||
import com.commafeed.backend.dao.UnitOfWork;
|
import com.commafeed.backend.dao.UnitOfWork;
|
||||||
import com.commafeed.backend.model.Feed;
|
import com.commafeed.backend.model.Feed;
|
||||||
|
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Contains utility methods for cleaning the database
|
* Contains utility methods for cleaning the database
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@RequiredArgsConstructor(onConstructor = @__({ @Inject }))
|
@RequiredArgsConstructor(onConstructor = @__({ @Inject }) )
|
||||||
@Singleton
|
@Singleton
|
||||||
public class DatabaseCleaningService {
|
public class DatabaseCleaningService {
|
||||||
|
|
||||||
@@ -42,16 +42,16 @@ public class DatabaseCleaningService {
|
|||||||
int deleted = 0;
|
int deleted = 0;
|
||||||
long entriesTotal = 0;
|
long entriesTotal = 0;
|
||||||
do {
|
do {
|
||||||
List<Feed> feeds = UnitOfWork.run(sessionFactory, () -> feedDAO.findWithoutSubscriptions(1));
|
List<Feed> feeds = UnitOfWork.call(sessionFactory, () -> feedDAO.findWithoutSubscriptions(1));
|
||||||
for (Feed feed : feeds) {
|
for (Feed feed : feeds) {
|
||||||
int entriesDeleted = 0;
|
int entriesDeleted = 0;
|
||||||
do {
|
do {
|
||||||
entriesDeleted = UnitOfWork.run(sessionFactory, () -> feedEntryDAO.delete(feed.getId(), BATCH_SIZE));
|
entriesDeleted = UnitOfWork.call(sessionFactory, () -> feedEntryDAO.delete(feed.getId(), BATCH_SIZE));
|
||||||
entriesTotal += entriesDeleted;
|
entriesTotal += entriesDeleted;
|
||||||
log.info("removed {} entries for feeds without subscriptions", entriesTotal);
|
log.info("removed {} entries for feeds without subscriptions", entriesTotal);
|
||||||
} while (entriesDeleted > 0);
|
} while (entriesDeleted > 0);
|
||||||
}
|
}
|
||||||
deleted = UnitOfWork.run(sessionFactory, () -> feedDAO.delete(feeds));
|
deleted = UnitOfWork.call(sessionFactory, () -> feedDAO.delete(feeds));
|
||||||
total += deleted;
|
total += deleted;
|
||||||
log.info("removed {} feeds without subscriptions", total);
|
log.info("removed {} feeds without subscriptions", total);
|
||||||
} while (deleted != 0);
|
} while (deleted != 0);
|
||||||
@@ -64,7 +64,7 @@ public class DatabaseCleaningService {
|
|||||||
long total = 0;
|
long total = 0;
|
||||||
int deleted = 0;
|
int deleted = 0;
|
||||||
do {
|
do {
|
||||||
deleted = UnitOfWork.run(sessionFactory, () -> feedEntryContentDAO.deleteWithoutEntries(BATCH_SIZE));
|
deleted = UnitOfWork.call(sessionFactory, () -> feedEntryContentDAO.deleteWithoutEntries(BATCH_SIZE));
|
||||||
total += deleted;
|
total += deleted;
|
||||||
log.info("removed {} contents without entries", total);
|
log.info("removed {} contents without entries", total);
|
||||||
} while (deleted != 0);
|
} while (deleted != 0);
|
||||||
@@ -75,7 +75,7 @@ public class DatabaseCleaningService {
|
|||||||
public long cleanEntriesForFeedsExceedingCapacity(final int maxFeedCapacity) {
|
public long cleanEntriesForFeedsExceedingCapacity(final int maxFeedCapacity) {
|
||||||
long total = 0;
|
long total = 0;
|
||||||
while (true) {
|
while (true) {
|
||||||
List<FeedCapacity> feeds = UnitOfWork.run(sessionFactory,
|
List<FeedCapacity> feeds = UnitOfWork.call(sessionFactory,
|
||||||
() -> feedEntryDAO.findFeedsExceedingCapacity(maxFeedCapacity, BATCH_SIZE));
|
() -> feedEntryDAO.findFeedsExceedingCapacity(maxFeedCapacity, BATCH_SIZE));
|
||||||
if (feeds.isEmpty()) {
|
if (feeds.isEmpty()) {
|
||||||
break;
|
break;
|
||||||
@@ -85,7 +85,7 @@ public class DatabaseCleaningService {
|
|||||||
long remaining = feed.getCapacity() - maxFeedCapacity;
|
long remaining = feed.getCapacity() - maxFeedCapacity;
|
||||||
do {
|
do {
|
||||||
final long rem = remaining;
|
final long rem = remaining;
|
||||||
int deleted = UnitOfWork.run(sessionFactory,
|
int deleted = UnitOfWork.call(sessionFactory,
|
||||||
() -> feedEntryDAO.deleteOldEntries(feed.getId(), Math.min(BATCH_SIZE, rem)));
|
() -> feedEntryDAO.deleteOldEntries(feed.getId(), Math.min(BATCH_SIZE, rem)));
|
||||||
total += deleted;
|
total += deleted;
|
||||||
remaining -= deleted;
|
remaining -= deleted;
|
||||||
@@ -102,7 +102,7 @@ public class DatabaseCleaningService {
|
|||||||
long total = 0;
|
long total = 0;
|
||||||
int deleted = 0;
|
int deleted = 0;
|
||||||
do {
|
do {
|
||||||
deleted = UnitOfWork.run(sessionFactory,
|
deleted = UnitOfWork.call(sessionFactory,
|
||||||
() -> feedEntryStatusDAO.delete(feedEntryStatusDAO.getOldStatuses(olderThan, BATCH_SIZE)));
|
() -> feedEntryStatusDAO.delete(feedEntryStatusDAO.getOldStatuses(olderThan, BATCH_SIZE)));
|
||||||
total += deleted;
|
total += deleted;
|
||||||
log.info("removed {} old read statuses", total);
|
log.info("removed {} old read statuses", total);
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
package com.commafeed.backend.service;
|
package com.commafeed.backend.service;
|
||||||
|
|
||||||
import io.dropwizard.lifecycle.Managed;
|
|
||||||
|
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
@@ -9,17 +7,6 @@ import javax.inject.Inject;
|
|||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
import javax.sql.DataSource;
|
import javax.sql.DataSource;
|
||||||
|
|
||||||
import liquibase.Liquibase;
|
|
||||||
import liquibase.database.Database;
|
|
||||||
import liquibase.database.DatabaseFactory;
|
|
||||||
import liquibase.database.core.PostgresDatabase;
|
|
||||||
import liquibase.database.jvm.JdbcConnection;
|
|
||||||
import liquibase.resource.ClassLoaderResourceAccessor;
|
|
||||||
import liquibase.resource.ResourceAccessor;
|
|
||||||
import liquibase.structure.DatabaseObject;
|
|
||||||
import lombok.RequiredArgsConstructor;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
|
|
||||||
import org.hibernate.SessionFactory;
|
import org.hibernate.SessionFactory;
|
||||||
import org.hibernate.engine.jdbc.connections.internal.DatasourceConnectionProviderImpl;
|
import org.hibernate.engine.jdbc.connections.internal.DatasourceConnectionProviderImpl;
|
||||||
import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider;
|
import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider;
|
||||||
@@ -31,8 +18,20 @@ import com.commafeed.backend.dao.UnitOfWork;
|
|||||||
import com.commafeed.backend.dao.UserDAO;
|
import com.commafeed.backend.dao.UserDAO;
|
||||||
import com.commafeed.backend.model.UserRole.Role;
|
import com.commafeed.backend.model.UserRole.Role;
|
||||||
|
|
||||||
|
import io.dropwizard.lifecycle.Managed;
|
||||||
|
import liquibase.Liquibase;
|
||||||
|
import liquibase.database.Database;
|
||||||
|
import liquibase.database.DatabaseFactory;
|
||||||
|
import liquibase.database.core.PostgresDatabase;
|
||||||
|
import liquibase.database.jvm.JdbcConnection;
|
||||||
|
import liquibase.resource.ClassLoaderResourceAccessor;
|
||||||
|
import liquibase.resource.ResourceAccessor;
|
||||||
|
import liquibase.structure.DatabaseObject;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@RequiredArgsConstructor(onConstructor = @__({ @Inject }))
|
@RequiredArgsConstructor(onConstructor = @__({ @Inject }) )
|
||||||
@Singleton
|
@Singleton
|
||||||
public class StartupService implements Managed {
|
public class StartupService implements Managed {
|
||||||
|
|
||||||
@@ -44,7 +43,7 @@ public class StartupService implements Managed {
|
|||||||
@Override
|
@Override
|
||||||
public void start() throws Exception {
|
public void start() throws Exception {
|
||||||
updateSchema();
|
updateSchema();
|
||||||
long count = UnitOfWork.run(sessionFactory, () -> userDAO.count());
|
long count = UnitOfWork.call(sessionFactory, () -> userDAO.count());
|
||||||
if (count == 0) {
|
if (count == 0) {
|
||||||
UnitOfWork.run(sessionFactory, () -> initialData());
|
UnitOfWork.run(sessionFactory, () -> initialData());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,8 +10,6 @@ import javax.servlet.http.HttpServlet;
|
|||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
import lombok.RequiredArgsConstructor;
|
|
||||||
|
|
||||||
import org.hibernate.SessionFactory;
|
import org.hibernate.SessionFactory;
|
||||||
|
|
||||||
import com.commafeed.backend.dao.UnitOfWork;
|
import com.commafeed.backend.dao.UnitOfWork;
|
||||||
@@ -20,8 +18,10 @@ import com.commafeed.backend.model.User;
|
|||||||
import com.commafeed.backend.model.UserSettings;
|
import com.commafeed.backend.model.UserSettings;
|
||||||
import com.commafeed.frontend.session.SessionHelper;
|
import com.commafeed.frontend.session.SessionHelper;
|
||||||
|
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
|
||||||
@SuppressWarnings("serial")
|
@SuppressWarnings("serial")
|
||||||
@RequiredArgsConstructor(onConstructor = @__({ @Inject }))
|
@RequiredArgsConstructor(onConstructor = @__({ @Inject }) )
|
||||||
@Singleton
|
@Singleton
|
||||||
public class CustomCssServlet extends HttpServlet {
|
public class CustomCssServlet extends HttpServlet {
|
||||||
|
|
||||||
@@ -37,7 +37,7 @@ public class CustomCssServlet extends HttpServlet {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
UserSettings settings = UnitOfWork.run(sessionFactory, () -> userSettingsDAO.findByUser(user.get()));
|
UserSettings settings = UnitOfWork.call(sessionFactory, () -> userSettingsDAO.findByUser(user.get()));
|
||||||
if (settings == null || settings.getCustomCss() == null) {
|
if (settings == null || settings.getCustomCss() == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,8 +11,6 @@ import javax.servlet.http.HttpServlet;
|
|||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
import lombok.RequiredArgsConstructor;
|
|
||||||
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.hibernate.SessionFactory;
|
import org.hibernate.SessionFactory;
|
||||||
|
|
||||||
@@ -31,8 +29,10 @@ import com.commafeed.frontend.resource.CategoryREST;
|
|||||||
import com.commafeed.frontend.session.SessionHelper;
|
import com.commafeed.frontend.session.SessionHelper;
|
||||||
import com.google.common.collect.Iterables;
|
import com.google.common.collect.Iterables;
|
||||||
|
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
|
||||||
@SuppressWarnings("serial")
|
@SuppressWarnings("serial")
|
||||||
@RequiredArgsConstructor(onConstructor = @__({ @Inject }))
|
@RequiredArgsConstructor(onConstructor = @__({ @Inject }) )
|
||||||
@Singleton
|
@Singleton
|
||||||
public class NextUnreadServlet extends HttpServlet {
|
public class NextUnreadServlet extends HttpServlet {
|
||||||
|
|
||||||
@@ -63,31 +63,29 @@ public class NextUnreadServlet extends HttpServlet {
|
|||||||
|
|
||||||
final ReadingOrder order = StringUtils.equals(orderParam, "asc") ? ReadingOrder.asc : ReadingOrder.desc;
|
final ReadingOrder order = StringUtils.equals(orderParam, "asc") ? ReadingOrder.asc : ReadingOrder.desc;
|
||||||
|
|
||||||
FeedEntryStatus status = UnitOfWork.run(
|
FeedEntryStatus status = UnitOfWork.call(sessionFactory, () -> {
|
||||||
sessionFactory,
|
FeedEntryStatus s = null;
|
||||||
() -> {
|
if (StringUtils.isBlank(categoryId) || CategoryREST.ALL.equals(categoryId)) {
|
||||||
FeedEntryStatus s = null;
|
List<FeedSubscription> subs = feedSubscriptionDAO.findAll(user.get());
|
||||||
if (StringUtils.isBlank(categoryId) || CategoryREST.ALL.equals(categoryId)) {
|
List<FeedEntryStatus> statuses = feedEntryStatusDAO.findBySubscriptions(user.get(), subs, true, null, null, 0, 1, order,
|
||||||
List<FeedSubscription> subs = feedSubscriptionDAO.findAll(user.get());
|
true, false, null);
|
||||||
List<FeedEntryStatus> statuses = feedEntryStatusDAO.findBySubscriptions(user.get(), subs, true, null, null, 0, 1,
|
s = Iterables.getFirst(statuses, null);
|
||||||
order, true, false, null);
|
} else {
|
||||||
s = Iterables.getFirst(statuses, null);
|
FeedCategory category = feedCategoryDAO.findById(user.get(), Long.valueOf(categoryId));
|
||||||
} else {
|
if (category != null) {
|
||||||
FeedCategory category = feedCategoryDAO.findById(user.get(), Long.valueOf(categoryId));
|
List<FeedCategory> children = feedCategoryDAO.findAllChildrenCategories(user.get(), category);
|
||||||
if (category != null) {
|
List<FeedSubscription> subscriptions = feedSubscriptionDAO.findByCategories(user.get(), children);
|
||||||
List<FeedCategory> children = feedCategoryDAO.findAllChildrenCategories(user.get(), category);
|
List<FeedEntryStatus> statuses = feedEntryStatusDAO.findBySubscriptions(user.get(), subscriptions, true, null, null, 0,
|
||||||
List<FeedSubscription> subscriptions = feedSubscriptionDAO.findByCategories(user.get(), children);
|
1, order, true, false, null);
|
||||||
List<FeedEntryStatus> statuses = feedEntryStatusDAO.findBySubscriptions(user.get(), subscriptions, true, null,
|
s = Iterables.getFirst(statuses, null);
|
||||||
null, 0, 1, order, true, false, null);
|
}
|
||||||
s = Iterables.getFirst(statuses, null);
|
}
|
||||||
}
|
if (s != null) {
|
||||||
}
|
s.setRead(true);
|
||||||
if (s != null) {
|
feedEntryStatusDAO.saveOrUpdate(s);
|
||||||
s.setRead(true);
|
}
|
||||||
feedEntryStatusDAO.saveOrUpdate(s);
|
return s;
|
||||||
}
|
});
|
||||||
return s;
|
|
||||||
});
|
|
||||||
|
|
||||||
if (status == null) {
|
if (status == null) {
|
||||||
resp.sendRedirect(resp.encodeRedirectURL(config.getApplicationSettings().getPublicUrl()));
|
resp.sendRedirect(resp.encodeRedirectURL(config.getApplicationSettings().getPublicUrl()));
|
||||||
|
|||||||
Reference in New Issue
Block a user