Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Service triggering N+1 queries
void logMessages() {
// Get all the messages from the database
// -> Triggers 1 query
Set<Message> messages = messageDao.findAll();
// Map through the N messages to create the DTO with the author display name
// -> Triggers 1 query to fetch each author so N queries!
messages.stream.map(
message -> logger.info(
message.getAuthor().getName() + ": " + message.getText()
)
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.