fix(dashboard): bulk-load document titles in getActivity to avoid N+1

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Marcel
2026-04-19 21:24:39 +02:00
parent 09a8081e35
commit 3f773cd9c3
3 changed files with 49 additions and 7 deletions

View File

@@ -124,12 +124,11 @@ public class DashboardService {
.toList();
Map<UUID, String> titleCache = new HashMap<>();
for (UUID docId : docIds) {
try {
titleCache.put(docId, documentService.getDocumentById(docId).getTitle());
} catch (Exception e) {
titleCache.put(docId, "");
}
try {
documentService.getDocumentsByIds(docIds)
.forEach(d -> titleCache.put(d.getId(), d.getTitle()));
} catch (Exception e) {
log.warn("Activity: failed to bulk-load document titles", e);
}
return rows.stream().map(row -> {

View File

@@ -484,6 +484,10 @@ public class DocumentService {
return doc;
}
public List<Document> getDocumentsByIds(List<UUID> ids) {
return documentRepository.findAllById(ids);
}
public List<Document> getDocumentsWithoutVersions() {
return documentRepository.findDocumentsWithoutVersions();
}