Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

fixes Bug mit MySQL Deadlock beim Mutli-File-Upload: Die Subquery im …

…Insert hat bei paralleler Verarbeitung Probleme gemacht
  • Loading branch information...
commit fa07f927b6aec6866af5d89f911ab32a45ddecd0 1 parent 1a99e99
@KyleRogers authored
Showing with 29 additions and 5 deletions.
  1. +29 −5 app/model/Fotoalbum.scala
View
34 app/model/Fotoalbum.scala
@@ -90,16 +90,40 @@ class PersistenterFotoalbenVerwalter extends FotoalbenVerwalter {
}
def speichereFotoFuerBenutzer(foto: Array[Byte], besitzer: Benutzer) {
- DB.withConnection { implicit connection =>
- SQL(
+ val insertedId = DB.withTransaction { implicit connection =>
+ val pos = SQL(
+ """SELECT COUNT(*)+1 FROM
+ ( SELECT id FROM fotos f
+ WHERE f.besitzer={besitzerid}
+ ORDER BY f.id
+ FOR UPDATE ) r """
+ ).on(
+ 'besitzerid -> besitzer.id
+ ).as(scalar[Long].single)
+
+ val insertId = SQL(
"""
INSERT INTO fotos (besitzer, foto, position) VALUES
- ( {besitzerid}, {foto}, (SELECT COUNT(*)+1 FROM fotos f2 WHERE f2.besitzer={besitzerid}) )
+ ( {besitzerid}, {foto}, {pos} )
"""
).on(
'besitzerid -> besitzer.id,
- 'foto -> foto
- ).executeUpdate()
+ 'foto -> new Array[Byte](2),
+ 'pos -> pos
+ ).executeInsert()
+
+ insertId
+ }
+
+ DB.withConnection { implicit connection =>
+ SQL(
+ """
+ UPDATE fotos SET foto = {foto} WHERE id = {id}
+ """
+ ).on(
+ 'id -> insertedId,
+ 'foto -> foto
+ ).executeUpdate()
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.