From 7d5e5eb75b424da3e1d22b0efc26a76796f1e9fd Mon Sep 17 00:00:00 2001 From: Gustavo Trott Date: Wed, 23 Oct 2024 21:57:03 -0300 Subject: [PATCH] fix insertOrUpdate causing conflict when sending in batch --- .../core/db/PresAnnotationDAO.scala | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/db/PresAnnotationDAO.scala b/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/db/PresAnnotationDAO.scala index 8f8bb533c2..eed5d70ed0 100644 --- a/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/db/PresAnnotationDAO.scala +++ b/akka-bbb-apps/src/main/scala/org/bigbluebutton/core/db/PresAnnotationDAO.scala @@ -28,16 +28,17 @@ object PresAnnotationDAO { annotation <- annotations } yield { DatabaseConnection.enqueue( - TableQuery[PresAnnotationDbTableDef].insertOrUpdate( - PresAnnotationDbModel( - annotationId = annotation.id, - pageId = annotation.wbId, - meetingId = meetingId, - userId = annotation.userId, - annotationInfo = JsonUtils.mapToJson(annotation.annotationInfo).compactPrint, - lastUpdatedAt = new java.sql.Timestamp(annotationUpdatedAt) - ) - ) + sqlu""" + WITH upsert AS ( + UPDATE pres_annotation + SET "annotationInfo"=${JsonUtils.mapToJson(annotation.annotationInfo).compactPrint}, + "lastUpdatedAt" = ${new java.sql.Timestamp(annotationUpdatedAt)} + WHERE "annotationId" = ${annotation.id} + RETURNING *) + INSERT INTO pres_annotation ("annotationId", "pageId", "meetingId", "userId", "annotationInfo", "lastUpdatedAt") + SELECT ${annotation.id}, ${annotation.wbId}, ${meetingId}, ${annotation.userId}, + ${JsonUtils.mapToJson(annotation.annotationInfo).compactPrint}, ${new java.sql.Timestamp(annotationUpdatedAt)} + WHERE NOT EXISTS (SELECT * FROM upsert)""" ) } }