/kotlin-spring:kotlin-read-path-performancefrom kotlin-spring
MUST use when writing, editing, or reviewing Kotlin/Spring Boot database access code: JPA or Spring Data repositories, @Query JPQL or native SQL, entity graphs or JOIN FETCH, projections/DTOs, @Transactional services, or controllers/services that return lists, search results, pagination, KPIs, summaries, or dashboards. Also use when hunting N+1 queries, slow endpoints, or high memory on read paths.
Ships in kotlin-spring. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
Goal for read operations: fewest DB round-trips, least memory, work pushed to the database.
findByIdWithItems, JOIN FETCH o.items).OrderSummaryRow) or DTOs via JPQL/native SQL.EXISTS (SELECT 1 FROM ...) in SQL, not .filter { } / .any { } on loaded lists.COUNT, SUM, GROUP BY in the database, not in Kotlin.SUM them in the outer query. Some dialects (notably SQL Server) reject SUM(CASE WHEN EXISTS (...) ...) in a single aggregate.@Service inside .map / .forEach loops.IN (:ids) query into a Map<Id, Data> and join in memory.IN lists: max 1,000 IDs per batch (ids.chunked(1000)). Dialect limits: SQL Server ~2,100 bind parameters per statement; Oracle 1,000 items per IN list.IN guard in native SQL: an empty list is invalid SQL in most dialects. Pass a flag, e.g. (:idsEmpty = 1 OR t.id IN (:ids)), or skip the query in Kotlin when the list is empty.Pageable returning Page<T> (implicit COUNT(*)) on large tables; prefer Slice<T> or the pattern below.size + 1: fetch limit = size + 1. If size + 1 rows come back, drop the last and set hasNext = true; otherwise hasNext = false.INNER JOIN required detail tables in the page query when a row must exist, so the page does not shrink after Kotlin discards rows.JOIN FETCH everything in the page query.@Transactional(readOnly = true) at class level on read-only services; override with @Transactional on write methods only.Reject and fix immediately:
| Anti-pattern | Fix |
|---|---|
JOIN FETCH in paginated list queries (Hibernate paginates in memory, warns HHH90003004) | Projections + two-phase hydration |
@Service/repository calls inside list-mapping loops | Single batched IN query + map join |
@Entity returned from controllers | DTO/response types only |
| Kotlin-side filtering/counting of loaded rows | WHERE EXISTS, COUNT, SUM in SQL |
// Bad: paginated list with JOIN FETCH
@Query("SELECT o FROM Order o JOIN FETCH o.items WHERE ...")
fun findPage(...): List<Order>
// Good: phase 1 returns page rows only
fun findOrderPage(..., limit: Int): List<OrderPageRow>
// phase 2: one batched query for the page's IDs
val itemsById = itemQueries.loadForIds(pageIds).groupBy { it.orderId }
What SKILL.md sets; muted values are Claude Code's defaults
Other plugins' skills for the same job
npx claudepluginhub altmgo/skills --plugin kotlin-spring