fix formatting

This commit is contained in:
Athou
2022-01-02 21:32:40 +01:00
parent b132178228
commit 78b637c83b
15 changed files with 642 additions and 615 deletions

View File

@@ -141,7 +141,9 @@ public class CommaFeedApplication extends Application<CommaFeedConfiguration> {
// Scheduled tasks // Scheduled tasks
Set<ScheduledTask> tasks = injector.getInstance(Key.get(new TypeLiteral<Set<ScheduledTask>>() { Set<ScheduledTask> tasks = injector.getInstance(Key.get(new TypeLiteral<Set<ScheduledTask>>() {
})); }));
ScheduledExecutorService executor = environment.lifecycle().scheduledExecutorService("task-scheduler", true).threads(tasks.size()) ScheduledExecutorService executor = environment.lifecycle()
.scheduledExecutorService("task-scheduler", true)
.threads(tasks.size())
.build(); .build();
for (ScheduledTask task : tasks) { for (ScheduledTask task : tasks) {
task.register(executor); task.register(executor);

View File

@@ -16,8 +16,8 @@ import com.querydsl.jpa.JPQLQuery;
@Singleton @Singleton
public class FeedEntryContentDAO extends GenericDAO<FeedEntryContent> { public class FeedEntryContentDAO extends GenericDAO<FeedEntryContent> {
private QFeedEntryContent content = QFeedEntryContent.feedEntryContent; private final QFeedEntryContent content = QFeedEntryContent.feedEntryContent;
private QFeedEntry entry = QFeedEntry.feedEntry; private final QFeedEntry entry = QFeedEntry.feedEntry;
@Inject @Inject
public FeedEntryContentDAO(SessionFactory sessionFactory) { public FeedEntryContentDAO(SessionFactory sessionFactory) {
@@ -25,7 +25,9 @@ public class FeedEntryContentDAO extends GenericDAO<FeedEntryContent> {
} }
public Long findExisting(String contentHash, String titleHash) { public Long findExisting(String contentHash, String titleHash) {
return query().select(content.id).from(content).where(content.contentHash.eq(contentHash), content.titleHash.eq(titleHash)) return query().select(content.id)
.from(content)
.where(content.contentHash.eq(contentHash), content.titleHash.eq(titleHash))
.fetchFirst(); .fetchFirst();
} }

View File

@@ -29,13 +29,20 @@ public class FeedEntryDAO extends GenericDAO<FeedEntry> {
} }
public Long findExisting(String guid, Feed feed) { public Long findExisting(String guid, Feed feed) {
return query().select(entry.id).from(entry).where(entry.guidHash.eq(DigestUtils.sha1Hex(guid)), entry.feed.eq(feed)).limit(1) return query().select(entry.id)
.from(entry)
.where(entry.guidHash.eq(DigestUtils.sha1Hex(guid)), entry.feed.eq(feed))
.limit(1)
.fetchOne(); .fetchOne();
} }
public List<FeedCapacity> findFeedsExceedingCapacity(long maxCapacity, long max) { public List<FeedCapacity> findFeedsExceedingCapacity(long maxCapacity, long max) {
NumberExpression<Long> count = entry.id.count(); NumberExpression<Long> count = entry.id.count();
List<Tuple> tuples = query().select(entry.feed.id, count).from(entry).groupBy(entry.feed).having(count.gt(maxCapacity)).limit(max) List<Tuple> tuples = query().select(entry.feed.id, count)
.from(entry)
.groupBy(entry.feed)
.having(count.gt(maxCapacity))
.limit(max)
.fetch(); .fetch();
return tuples.stream().map(t -> new FeedCapacity(t.get(entry.feed.id), t.get(count))).collect(Collectors.toList()); return tuples.stream().map(t -> new FeedCapacity(t.get(entry.feed.id), t.get(count))).collect(Collectors.toList());
} }

View File

@@ -29,8 +29,13 @@ public class FeedSubscriptionDAO extends GenericDAO<FeedSubscription> {
} }
public FeedSubscription findById(User user, Long id) { public FeedSubscription findById(User user, Long id) {
List<FeedSubscription> subs = query().selectFrom(sub).where(sub.user.eq(user), sub.id.eq(id)).leftJoin(sub.feed).fetchJoin() List<FeedSubscription> subs = query().selectFrom(sub)
.leftJoin(sub.category).fetchJoin().fetch(); .where(sub.user.eq(user), sub.id.eq(id))
.leftJoin(sub.feed)
.fetchJoin()
.leftJoin(sub.category)
.fetchJoin()
.fetch();
return initRelations(Iterables.getFirst(subs, null)); return initRelations(Iterables.getFirst(subs, null));
} }
@@ -44,8 +49,13 @@ public class FeedSubscriptionDAO extends GenericDAO<FeedSubscription> {
} }
public List<FeedSubscription> findAll(User user) { public List<FeedSubscription> findAll(User user) {
List<FeedSubscription> subs = query().selectFrom(sub).where(sub.user.eq(user)).leftJoin(sub.feed).fetchJoin().leftJoin(sub.category) List<FeedSubscription> subs = query().selectFrom(sub)
.fetchJoin().fetch(); .where(sub.user.eq(user))
.leftJoin(sub.feed)
.fetchJoin()
.leftJoin(sub.category)
.fetchJoin()
.fetch();
return initRelations(subs); return initRelations(subs);
} }
@@ -61,7 +71,8 @@ public class FeedSubscriptionDAO extends GenericDAO<FeedSubscription> {
public List<FeedSubscription> findByCategories(User user, List<FeedCategory> categories) { public List<FeedSubscription> findByCategories(User user, List<FeedCategory> categories) {
Set<Long> categoryIds = categories.stream().map(c -> c.getId()).collect(Collectors.toSet()); Set<Long> categoryIds = categories.stream().map(c -> c.getId()).collect(Collectors.toSet());
return findAll(user).stream().filter(s -> s.getCategory() != null && categoryIds.contains(s.getCategory().getId())) return findAll(user).stream()
.filter(s -> s.getCategory() != null && categoryIds.contains(s.getCategory().getId()))
.collect(Collectors.toList()); .collect(Collectors.toList());
} }

View File

@@ -61,13 +61,15 @@ public class OPMLExporter {
outline.setText(cat.getName()); outline.setText(cat.getName());
outline.setTitle(cat.getName()); outline.setTitle(cat.getName());
for (FeedCategory child : categories.stream().filter(c -> c.getParent() != null && c.getParent().getId().equals(cat.getId())) for (FeedCategory child : categories.stream()
.filter(c -> c.getParent() != null && c.getParent().getId().equals(cat.getId()))
.collect(Collectors.toList())) { .collect(Collectors.toList())) {
outline.getChildren().add(buildCategoryOutline(child, categories, subscriptions)); outline.getChildren().add(buildCategoryOutline(child, categories, subscriptions));
} }
for (FeedSubscription sub : subscriptions.stream() for (FeedSubscription sub : subscriptions.stream()
.filter(s -> s.getCategory() != null && s.getCategory().getId().equals(cat.getId())).collect(Collectors.toList())) { .filter(s -> s.getCategory() != null && s.getCategory().getId().equals(cat.getId()))
.collect(Collectors.toList())) {
outline.getChildren().add(buildSubscriptionOutline(sub)); outline.getChildren().add(buildSubscriptionOutline(sub));
} }
return outline; return outline;

View File

@@ -26,8 +26,8 @@ public abstract class ScheduledTask {
} }
} }
}; };
log.info("registering task {} for execution every {} {}, starting in {} {}", getClass().getSimpleName(), getPeriod(), log.info("registering task {} for execution every {} {}, starting in {} {}", getClass().getSimpleName(), getPeriod(), getTimeUnit(),
getTimeUnit(), getInitialDelay(), getTimeUnit()); getInitialDelay(), getTimeUnit());
executor.scheduleWithFixedDelay(runnable, getInitialDelay(), getPeriod(), getTimeUnit()); executor.scheduleWithFixedDelay(runnable, getInitialDelay(), getPeriod(), getTimeUnit());
} }
} }

View File

@@ -145,16 +145,18 @@ public class CategoryREST {
offset, limit + 1, order, true, onlyIds, tag); offset, limit + 1, order, true, onlyIds, tag);
for (FeedEntryStatus status : list) { for (FeedEntryStatus status : list) {
entries.getEntries().add(Entry.build(status, config.getApplicationSettings().getPublicUrl(), entries.getEntries()
config.getApplicationSettings().getImageProxyEnabled())); .add(Entry.build(status, config.getApplicationSettings().getPublicUrl(),
config.getApplicationSettings().getImageProxyEnabled()));
} }
} else if (STARRED.equals(id)) { } else if (STARRED.equals(id)) {
entries.setName("Starred"); entries.setName("Starred");
List<FeedEntryStatus> starred = feedEntryStatusDAO.findStarred(user, newerThanDate, offset, limit + 1, order, !onlyIds); List<FeedEntryStatus> starred = feedEntryStatusDAO.findStarred(user, newerThanDate, offset, limit + 1, order, !onlyIds);
for (FeedEntryStatus status : starred) { for (FeedEntryStatus status : starred) {
entries.getEntries().add(Entry.build(status, config.getApplicationSettings().getPublicUrl(), entries.getEntries()
config.getApplicationSettings().getImageProxyEnabled())); .add(Entry.build(status, config.getApplicationSettings().getPublicUrl(),
config.getApplicationSettings().getImageProxyEnabled()));
} }
} else { } else {
FeedCategory parent = feedCategoryDAO.findById(user, Long.valueOf(id)); FeedCategory parent = feedCategoryDAO.findById(user, Long.valueOf(id));
@@ -166,8 +168,9 @@ public class CategoryREST {
offset, limit + 1, order, true, onlyIds, tag); offset, limit + 1, order, true, onlyIds, tag);
for (FeedEntryStatus status : list) { for (FeedEntryStatus status : list) {
entries.getEntries().add(Entry.build(status, config.getApplicationSettings().getPublicUrl(), entries.getEntries()
config.getApplicationSettings().getImageProxyEnabled())); .add(Entry.build(status, config.getApplicationSettings().getPublicUrl(),
config.getApplicationSettings().getImageProxyEnabled()));
} }
entries.setName(parent.getName()); entries.setName(parent.getName());
} else { } else {