Improve insert of annotations to send it in batch

This commit is contained in:
Gustavo Trott 2024-10-23 17:32:38 -03:00
parent 60c15006f2
commit 392953f08e
3 changed files with 25 additions and 59 deletions

View File

@ -23,28 +23,23 @@ class PresAnnotationDbTableDef(tag: Tag) extends Table[PresAnnotationDbModel](ta
} }
object PresAnnotationDAO { object PresAnnotationDAO {
def prepareInsertOrUpdate(meetingId: String, annotation: AnnotationVO, annotationUpdatedAt: Long) = {
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)
)
)
}
def insertOrUpdateMap(meetingId: String, annotations: Array[AnnotationVO], annotationUpdatedAt: Long) = { def insertOrUpdateMap(meetingId: String, annotations: Array[AnnotationVO], annotationUpdatedAt: Long) = {
DatabaseConnection.enqueue( for {
DBIO.sequence( annotation <- annotations
annotations.map { annotation => } yield {
prepareInsertOrUpdate(meetingId, annotation, annotationUpdatedAt) DatabaseConnection.enqueue(
}.toVector TableQuery[PresAnnotationDbTableDef].insertOrUpdate(
).transactionally PresAnnotationDbModel(
) annotationId = annotation.id,
pageId = annotation.wbId,
meetingId = meetingId,
userId = annotation.userId,
annotationInfo = JsonUtils.mapToJson(annotation.annotationInfo).compactPrint,
lastUpdatedAt = new java.sql.Timestamp(annotationUpdatedAt)
)
)
)
}
} }
def deleteAnnotations(meetingId: String, userId: String, annotationIds: Array[String], annotationUpdatedAt: Long) = { def deleteAnnotations(meetingId: String, userId: String, annotationIds: Array[String], annotationUpdatedAt: Long) = {

View File

@ -24,24 +24,8 @@ class PresAnnotationHistoryDbTableDef(tag: Tag) extends Table[PresAnnotationHist
object PresAnnotationHistoryDAO { object PresAnnotationHistoryDAO {
def delete(wbId: String, meetingId: String, userId: String, annotationId: String, annotationUpdatedAt: Long) = { def insertOrUpdateMap(meetingId: String, annotations: Array[AnnotationVO], annotationUpdatedAt: Long) = {
DatabaseConnection.enqueue( val dbModels = annotations.map { annotation =>
TableQuery[PresAnnotationHistoryDbTableDef].forceInsert(
PresAnnotationHistoryDbModel(
// None,
annotationId = annotationId,
pageId = wbId,
meetingId = meetingId,
userId = userId,
annotationInfo = "",
updatedAt = new java.sql.Timestamp(annotationUpdatedAt)
)
)
)
}
def prepareInsertOrUpdate(meetingId: String, annotation: AnnotationVO, annotationUpdatedAt: Long) = {
TableQuery[PresAnnotationHistoryDbTableDef].forceInsert(
PresAnnotationHistoryDbModel( PresAnnotationHistoryDbModel(
annotationId = annotation.id, annotationId = annotation.id,
pageId = annotation.wbId, pageId = annotation.wbId,
@ -50,21 +34,14 @@ object PresAnnotationHistoryDAO {
annotationInfo = JsonUtils.mapToJson(annotation.annotationInfo).compactPrint, annotationInfo = JsonUtils.mapToJson(annotation.annotationInfo).compactPrint,
updatedAt = new java.sql.Timestamp(annotationUpdatedAt) updatedAt = new java.sql.Timestamp(annotationUpdatedAt)
) )
) }
}
def insertOrUpdateMap(meetingId: String, annotations: Array[AnnotationVO], annotationUpdatedAt: Long) = {
DatabaseConnection.enqueue( DatabaseConnection.enqueue(
DBIO.sequence( TableQuery[PresAnnotationHistoryDbTableDef] ++= dbModels
annotations.map { annotation =>
prepareInsertOrUpdate(meetingId, annotation, annotationUpdatedAt)
}.toVector
).transactionally
) )
} }
def prepareDelete(meetingId: String, pageId: String, annotationId: String, userId: String, annotationUpdatedAt: Long) = { def deleteAnnotations(meetingId: String, pageId: String, userId: String, annotations: Array[String], annotationUpdatedAt: Long) = {
TableQuery[PresAnnotationHistoryDbTableDef].forceInsert( val dbModels = annotations.map { annotationId =>
PresAnnotationHistoryDbModel( PresAnnotationHistoryDbModel(
annotationId = annotationId, annotationId = annotationId,
pageId = pageId, pageId = pageId,
@ -73,16 +50,11 @@ object PresAnnotationHistoryDAO {
annotationInfo = "", annotationInfo = "",
updatedAt = new java.sql.Timestamp(annotationUpdatedAt) updatedAt = new java.sql.Timestamp(annotationUpdatedAt)
) )
) }
}
def deleteAnnotations(meetingId: String, pageId: String, userId: String, annotations: Array[String], annotationUpdatedAt: Long) = {
DatabaseConnection.enqueue( DatabaseConnection.enqueue(
DBIO.sequence( TableQuery[PresAnnotationHistoryDbTableDef] ++= dbModels
annotations.map { annotationId =>
prepareDelete(meetingId, pageId, annotationId, userId, annotationUpdatedAt)
}.toVector
).transactionally
) )
} }
} }

View File

@ -111,7 +111,6 @@ export const CURRENT_PAGE_ANNOTATIONS_QUERY = gql`query CurrentPageAnnotationsQu
pres_annotation_curr(order_by: { lastUpdatedAt: desc }) { pres_annotation_curr(order_by: { lastUpdatedAt: desc }) {
annotationId annotationId
annotationInfo annotationInfo
lastHistorySequence
lastUpdatedAt lastUpdatedAt
pageId pageId
presentationId presentationId