Skip to content

Commit

Permalink
Optimize batch insert
Browse files Browse the repository at this point in the history
  • Loading branch information
gonmarques committed Mar 4, 2017
1 parent ac547c8 commit e1513d9
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,4 @@ private case class LifecycleHandlerCacheKey(clazz: Class[_ <: Repository[_, _]],

sealed abstract class LifecycleEvent(val functionName : String)
case object POSTLOAD extends LifecycleEvent("postLoad")
case object PREPERSIST extends LifecycleEvent("prePersist")
Original file line number Diff line number Diff line change
Expand Up @@ -132,13 +132,13 @@ abstract class Repository[T <: Entity[T, ID], ID](val driver: JdbcProfile) {
* Batch persister
*/
protected val batchPersister: Seq[T] => DBIO[Option[Int]] =
getBatchPersister(identity)
getBatchPersister(seq => sequenceLifecycleEvent(seq, prePersist, PREPERSIST))

/**
* Builds a batch persister
*/
protected def getBatchPersister(transformer: T => T): Seq[T] => DBIO[Option[Int]] =
(entities: Seq[T]) => tableQueryCompiled ++= entities.map(prePersist compose transformer)
protected def getBatchPersister(seqTransformer: Seq[T] => Seq[T]): Seq[T] => DBIO[Option[Int]] =
(entities: Seq[T]) => tableQueryCompiled ++= seqTransformer(entities)

/**
* Updates a given entity in the database.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ abstract class VersionedRepository[T <: VersionedEntity[T, ID, V], ID, V : Versi
* Batch persister
*/
override protected val batchPersister: Seq[T] => DBIO[Option[Int]] =
getBatchPersister(versionApplier)
getBatchPersister(entities => entities.map(prePersist compose versionApplier))

/**
* Updater
Expand Down

0 comments on commit e1513d9

Please sign in to comment.