optimisation: faster update of attempted column

Signed-off-by: hrj <harshad.rj@gmail.com>
This commit is contained in:
hrj 2021-04-19 01:01:15 +05:30
parent 4335740bfc
commit 7684b68efd
2 changed files with 4 additions and 7 deletions

View File

@ -96,7 +96,7 @@ object Captcha {
token match { token match {
case Some(value) => { case Some(value) => {
val uuid = getUUID(value) val uuid = getUUID(value)
updateAttempted(uuid) updateAttempted(value)
Right(Id(uuid)) Right(Id(uuid))
} }
case None => { case None => {
@ -121,9 +121,9 @@ object Captcha {
} }
} }
private def updateAttempted(uuid: String): Unit = { private def updateAttempted(token: Int): Unit = {
val updateAttemptedPstmt = Statements.tlStmts.get.updateAttemptedPstmt val updateAttemptedPstmt = Statements.tlStmts.get.updateAttemptedPstmt
updateAttemptedPstmt.setString(1, uuid) updateAttemptedPstmt.setInt(1, token)
updateAttemptedPstmt.executeUpdate() updateAttemptedPstmt.executeUpdate()
} }

View File

@ -64,10 +64,7 @@ class Statements(dbConn: DBConn, maxAttempts: Int) {
val updateAttemptedPstmt: PreparedStatement = dbConn.con.prepareStatement( val updateAttemptedPstmt: PreparedStatement = dbConn.con.prepareStatement(
"UPDATE challenge " + "UPDATE challenge " +
"SET attempted = attempted+1 " + "SET attempted = attempted+1 " +
"WHERE token = (SELECT m.token " + "WHERE token = ?;"
"FROM mapId m, challenge c " +
"WHERE m.token=c.token AND " +
"m.uuid = ?)"
) )
val tokenPstmt: PreparedStatement = dbConn.con.prepareStatement( val tokenPstmt: PreparedStatement = dbConn.con.prepareStatement(