Skip to content

Commit

Permalink
fix: fix n+1 problem kaomoji entity fetch (#8)
Browse files Browse the repository at this point in the history
* fix: fix N+1 request problem during `Kaomoji` entity fetch

Signed-off-by: ablandel <[email protected]>

* chore: add hibernates properties for future debug

Signed-off-by: ablandel <[email protected]>

---------

Signed-off-by: ablandel <[email protected]>
  • Loading branch information
ablandel committed Jun 12, 2024
1 parent eaddd9a commit 0127226
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ Add the changes here.

- Configuration of the default logger with rolling policy to trace server logs in a file

### Fix

- Fix N+1 request problem during `Kaomoji` entity fetch

## [1.1.0] - 2024-06-07

### Added
Expand Down
3 changes: 3 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ tasks.register("bootRunDev") {
systemProperty("logging.level.web", "info")
systemProperty("spring.mvc.log-request-details", true)
systemProperty("spring.codec.log-request-details", true)
systemProperty("spring.jpa.show-sql", true)
systemProperty("hibernate.generate_statistics", false)
systemProperty("hibernate.use_sql_comments", false)
}
}
finalizedBy("bootRun")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package github.ablandel.anotherkaomoji.entity

import jakarta.persistence.*
import org.hibernate.annotations.BatchSize
import java.time.Instant

@Entity(name = "kaomoji")
Expand All @@ -11,10 +12,15 @@ data class Kaomoji(
override var createdAt: Instant? = null,
override var updatedAt: Instant? = null,
@ManyToMany(cascade = [CascadeType.PERSIST])
@BatchSize(size = TAGS_BATCH_SIZE)
@JoinTable(
name = "kaomojis_tags",
joinColumns = [JoinColumn(name = "kaomoji_id")],
inverseJoinColumns = [JoinColumn(name = "tag_id")]
)
var tags: List<Tag>,
) : AbstractEntity()
) : AbstractEntity() {
companion object {
const val TAGS_BATCH_SIZE = 20
}
}

0 comments on commit 0127226

Please sign in to comment.