Skip to content

Commit 83e783c

Browse files
marc0derclaude
andcommitted
refactor: optimize HealthRepository database query with SELECT 1
Co-Authored-By: Claude <[email protected]>
1 parent 2c3e831 commit 83e783c

File tree

2 files changed

+3
-10
lines changed

2 files changed

+3
-10
lines changed

prompts/03-health_check_endpoint-todo.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Consider the following rules during execution of the tasks:
1616

1717
### Task 2: Optimize HealthRepository Database Query
1818

19-
- [ ] Replace versions table usage with proper SELECT 1 query for health checks
19+
- [X] Replace versions table usage with proper SELECT 1 query for health checks
2020

2121
**Prompt**: Optimize the HealthRepository implementation to address the TODO comment in `src/main/kotlin/io/sdkman/repos/HealthRepository.kt` at line 13. Replace the current approach that uses the versions table with a proper `SELECT 1` query using Exposed SQL strings as documented at https://www.jetbrains.com/help/exposed/working-with-sql-strings.html. The health check should not depend on any application tables and should use a simple database connectivity test instead.
2222

src/main/kotlin/io/sdkman/repos/HealthRepository.kt

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,17 @@ import arrow.core.Either
44
import io.sdkman.domain.DatabaseFailure
55
import io.sdkman.domain.HealthRepository
66
import kotlinx.coroutines.Dispatchers
7-
import org.jetbrains.exposed.dao.id.IntIdTable
8-
import org.jetbrains.exposed.sql.*
97
import org.jetbrains.exposed.sql.transactions.experimental.newSuspendedTransaction
8+
import org.jetbrains.exposed.sql.transactions.TransactionManager
109

1110
class HealthRepositoryImpl : HealthRepository {
1211

13-
//TODO: Don't use versions table! Use SELECT 1 query using the Exposed SQL strings:
14-
// (https://www.jetbrains.com/help/exposed/working-with-sql-strings.html)
15-
private object HealthCheck : IntIdTable(name = "versions") {
16-
// We'll use the existing versions table to check connectivity
17-
}
18-
1912
private suspend fun <T> dbQuery(block: suspend () -> T): T =
2013
newSuspendedTransaction(Dispatchers.IO) { block() }
2114

2215
override suspend fun checkDatabaseConnection(): Either<DatabaseFailure, Unit> = Either.catch {
2316
dbQuery {
24-
HealthCheck.selectAll().limit(1).count()
17+
TransactionManager.current().exec("SELECT 1")
2518
Unit
2619
}
2720
}.mapLeft { throwable ->

0 commit comments

Comments
 (0)