Skip to content

Commit

Permalink
improvement: avoid atomic double touch if not needed
Browse files Browse the repository at this point in the history
  • Loading branch information
spangaer authored and tgodzik committed Nov 21, 2024
1 parent 29c783a commit 8e5006f
Showing 1 changed file with 13 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,23 @@ class ChosenBuildTool(conn: () => Connection) {
)

def selectedBuildTool(): Option[String] = {
val selected = currentTool
.get()
.orElse(
conn()
currentTool.get() match {
case selected @ Some(_) =>
selected
case None =>
val selected = conn()
.query(
"select * from chosen_build_tool LIMIT 1;"
)(_ => ()) { _.getString("build_tool") }
.headOption
)
selected.flatMap(toolName =>
currentTool.updateAndGet {
case None => Some(toolName)
case some => some
}
)

selected.flatMap(toolName =>
currentTool.updateAndGet {
case None => Some(toolName)
case some => some
}
)
}
}

def chooseBuildTool(buildTool: String): Int = synchronized {
Expand Down

0 comments on commit 8e5006f

Please sign in to comment.