mirror of
https://github.com/Athou/commafeed.git
synced 2026-03-21 21:37:29 +00:00
fetch all tags at once
This commit is contained in:
@@ -3,6 +3,7 @@ package com.commafeed.backend.dao;
|
|||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import org.apache.commons.collections4.CollectionUtils;
|
import org.apache.commons.collections4.CollectionUtils;
|
||||||
import org.hibernate.SessionFactory;
|
import org.hibernate.SessionFactory;
|
||||||
@@ -73,10 +74,13 @@ public class FeedEntryStatusDAO extends GenericDAO<FeedEntryStatus> {
|
|||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
private FeedEntryStatus fetchTags(User user, FeedEntryStatus status) {
|
private void fetchTags(User user, List<FeedEntryStatus> statuses) {
|
||||||
List<FeedEntryTag> tags = feedEntryTagDAO.findByEntry(user, status.getEntry());
|
Map<Long, List<FeedEntryTag>> tagsByEntryIds = feedEntryTagDAO.findByEntries(user,
|
||||||
status.setTags(tags);
|
statuses.stream().map(FeedEntryStatus::getEntry).toList());
|
||||||
return status;
|
for (FeedEntryStatus status : statuses) {
|
||||||
|
List<FeedEntryTag> tags = tagsByEntryIds.get(status.getEntry().getId());
|
||||||
|
status.setTags(tags == null ? List.of() : tags);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<FeedEntryStatus> findStarred(User user, Instant newerThan, int offset, int limit, ReadingOrder order,
|
public List<FeedEntryStatus> findStarred(User user, Instant newerThan, int offset, int limit, ReadingOrder order,
|
||||||
@@ -107,12 +111,9 @@ public class FeedEntryStatusDAO extends GenericDAO<FeedEntryStatus> {
|
|||||||
setTimeout(query, config.getApplicationSettings().getQueryTimeout());
|
setTimeout(query, config.getApplicationSettings().getQueryTimeout());
|
||||||
|
|
||||||
List<FeedEntryStatus> statuses = query.fetch();
|
List<FeedEntryStatus> statuses = query.fetch();
|
||||||
for (FeedEntryStatus status : statuses) {
|
statuses.forEach(s -> s.setMarkable(true));
|
||||||
status.setMarkable(true);
|
if (includeContent) {
|
||||||
|
fetchTags(user, statuses);
|
||||||
if (includeContent) {
|
|
||||||
fetchTags(user, status);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return statuses;
|
return statuses;
|
||||||
@@ -190,14 +191,13 @@ public class FeedEntryStatusDAO extends GenericDAO<FeedEntryStatus> {
|
|||||||
FeedEntry e = tuple.get(entry);
|
FeedEntry e = tuple.get(entry);
|
||||||
FeedSubscription sub = tuple.get(subscription);
|
FeedSubscription sub = tuple.get(subscription);
|
||||||
FeedEntryStatus s = handleStatus(user, tuple.get(status), sub, e);
|
FeedEntryStatus s = handleStatus(user, tuple.get(status), sub, e);
|
||||||
|
|
||||||
if (includeContent) {
|
|
||||||
fetchTags(user, s);
|
|
||||||
}
|
|
||||||
|
|
||||||
statuses.add(s);
|
statuses.add(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (includeContent) {
|
||||||
|
fetchTags(user, statuses);
|
||||||
|
}
|
||||||
|
|
||||||
return statuses;
|
return statuses;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
package com.commafeed.backend.dao;
|
package com.commafeed.backend.dao;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import org.hibernate.SessionFactory;
|
import org.hibernate.SessionFactory;
|
||||||
|
|
||||||
@@ -29,4 +31,12 @@ public class FeedEntryTagDAO extends GenericDAO<FeedEntryTag> {
|
|||||||
public List<FeedEntryTag> findByEntry(User user, FeedEntry entry) {
|
public List<FeedEntryTag> findByEntry(User user, FeedEntry entry) {
|
||||||
return query().selectFrom(tag).where(tag.user.eq(user), tag.entry.eq(entry)).fetch();
|
return query().selectFrom(tag).where(tag.user.eq(user), tag.entry.eq(entry)).fetch();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Map<Long, List<FeedEntryTag>> findByEntries(User user, List<FeedEntry> entries) {
|
||||||
|
return query().selectFrom(tag)
|
||||||
|
.where(tag.user.eq(user), tag.entry.in(entries))
|
||||||
|
.fetch()
|
||||||
|
.stream()
|
||||||
|
.collect(Collectors.groupingBy(t -> t.getEntry().getId()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user