Skip to content

Commit

Permalink
[CTX-27] fix: count jobs artifacts before finding to avoid ES scrolls (
Browse files Browse the repository at this point in the history
  • Loading branch information
srottenberg authored Apr 25, 2024
1 parent 1d6ff42 commit ad6db0c
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion app/org/thp/cortex/services/JobSrv.scala
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,22 @@ class JobSrv(
): (Source[Artifact, NotUsed], Future[Long]) = {
import org.elastic4play.services.QueryDSL._
withUserFilter(userId) { organizationId =>
findSrv[ArtifactModel, Artifact](
def find(range: Option[String]): (Source[Artifact, NotUsed], Future[Long]) = findSrv[ArtifactModel, Artifact](
artifactModel,
and(queryDef, parent("report", parent("job", and(withId(jobId), "organization" ~= organizationId)))),
range,
sortBy
)

val count = find(Some("0-1"))._2
Source
.futureSource(count.map {
case 0L => Source.empty[Artifact]
case c if range.contains("all") => find(Some(s"0-$c"))._1
case _ => find(range)._1
})
.mapMaterializedValue(_ => NotUsed) -> count

}
}

Expand Down

0 comments on commit ad6db0c

Please sign in to comment.