Skip to content

Commit

Permalink
fix: pagination aggregation should always use the RAW-DAO
Browse files Browse the repository at this point in the history
  • Loading branch information
Simon Siedler committed Mar 31, 2023
1 parent 4f064b9 commit 0bf5dc9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ import scala.jdk.CollectionConverters._
case class MongoPaginatedAggregation[A <: Any](
dao: MongoDAO[A],
aggregationPipeline: List[Bson] = List(),
allowDiskUse: Boolean = false
allowDiskUse: Boolean = false,
maxWait: Int = DefaultMaxWait
) extends MongoPagination[Document] {

private val AggregationKeyMetaData = "metadata"
Expand All @@ -37,7 +38,7 @@ case class MongoPaginatedAggregation[A <: Any](
Aggregates.facet(new Facet(AggregationKeyMetaData, listOfMetaData.asJava), new Facet(AggregationKeyData, listOfPaging.asJava))
)

val dbResponse = dao.findAggregated(pipeline, allowDiskUse).result().asInstanceOf[Document]
val dbResponse = dao.Raw.findAggregated(pipeline, allowDiskUse).result(maxWait)

val count: Long = dbResponse.get(AggregationKeyMetaData).get.asArray().get(0).asDocument().get(AggregationKeyMetaDataTotal).asNumber().longValue()
val allPages = Math.ceil(count.toDouble / rows).toInt
Expand All @@ -52,7 +53,7 @@ case class MongoPaginatedAggregation[A <: Any](
val pipeline = aggregationPipeline ++ List(
Aggregates.facet(new Facet(AggregationKeyMetaData, listOfMetaData.asJava), new Facet(AggregationKeyData, listOfPaging.asJava))
)
val dbResponse = dao.findAggregated(pipeline, allowDiskUse).result().asInstanceOf[Document]
val dbResponse = dao.Raw.findAggregated(pipeline, allowDiskUse).result(maxWait)
val count: Long = dbResponse.get(AggregationKeyMetaData).get.asArray().get(0).asDocument().get(AggregationKeyMetaDataTotal).asNumber().longValue()
count
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class PaginationFilterSpec extends PersonSpecification with MongoImplicits {
val pageFemale = paginationFemale.paginate(1, 10)
// #endregion filter-pagination

paginationFemale.countResult mustEqual 11
paginationFemale.countResult mustEqual 98
pageFemale.paginationInfo.pagesCount mustEqual 10
pageFemale.paginationInfo.allCount mustEqual 98
pageFemale.paginationInfo.page mustEqual 1
Expand All @@ -46,7 +46,7 @@ class PaginationFilterSpec extends PersonSpecification with MongoImplicits {
val paginationMales = MongoPaginatedFilter(PersonDAO, Map("gender" -> "male"))
val pageMale = paginationMales.paginate(1, 10)

paginationMales.countResult mustEqual 11
paginationMales.countResult mustEqual 102
pageMale.paginationInfo.pagesCount mustEqual 11
pageMale.paginationInfo.allCount mustEqual 102
pageMale.paginationInfo.page mustEqual 1
Expand Down

0 comments on commit 0bf5dc9

Please sign in to comment.