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 {
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) = {
DatabaseConnection.enqueue(
DBIO.sequence(
annotations.map { annotation =>
prepareInsertOrUpdate(meetingId, annotation, annotationUpdatedAt)
}.toVector
).transactionally
)
for {
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)
)
)
)
}
}
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 {
def delete(wbId: String, meetingId: String, userId: String, annotationId: String, annotationUpdatedAt: Long) = {
DatabaseConnection.enqueue(
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(
def insertOrUpdateMap(meetingId: String, annotations: Array[AnnotationVO], annotationUpdatedAt: Long) = {
val dbModels = annotations.map { annotation =>
PresAnnotationHistoryDbModel(
annotationId = annotation.id,
pageId = annotation.wbId,
@ -50,21 +34,14 @@ object PresAnnotationHistoryDAO {
annotationInfo = JsonUtils.mapToJson(annotation.annotationInfo).compactPrint,
updatedAt = new java.sql.Timestamp(annotationUpdatedAt)
)
)
}
def insertOrUpdateMap(meetingId: String, annotations: Array[AnnotationVO], annotationUpdatedAt: Long) = {
}
DatabaseConnection.enqueue(
DBIO.sequence(
annotations.map { annotation =>
prepareInsertOrUpdate(meetingId, annotation, annotationUpdatedAt)
}.toVector
).transactionally
TableQuery[PresAnnotationHistoryDbTableDef] ++= dbModels
)
}
def prepareDelete(meetingId: String, pageId: String, annotationId: String, userId: String, annotationUpdatedAt: Long) = {
TableQuery[PresAnnotationHistoryDbTableDef].forceInsert(
def deleteAnnotations(meetingId: String, pageId: String, userId: String, annotations: Array[String], annotationUpdatedAt: Long) = {
val dbModels = annotations.map { annotationId =>
PresAnnotationHistoryDbModel(
annotationId = annotationId,
pageId = pageId,
@ -73,16 +50,11 @@ object PresAnnotationHistoryDAO {
annotationInfo = "",
updatedAt = new java.sql.Timestamp(annotationUpdatedAt)
)
)
}
}
def deleteAnnotations(meetingId: String, pageId: String, userId: String, annotations: Array[String], annotationUpdatedAt: Long) = {
DatabaseConnection.enqueue(
DBIO.sequence(
annotations.map { annotationId =>
prepareDelete(meetingId, pageId, annotationId, userId, annotationUpdatedAt)
}.toVector
).transactionally
TableQuery[PresAnnotationHistoryDbTableDef] ++= dbModels
)
}
}

View File

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