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:
@@ -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 -> {
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user