Skip to content

Commit ad6db0c

Browse files
authored
[CTX-27] fix: count jobs artifacts before finding to avoid ES scrolls (#468)
1 parent 1d6ff42 commit ad6db0c

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

app/org/thp/cortex/services/JobSrv.scala

+11-1
Original file line numberDiff line numberDiff line change
@@ -128,12 +128,22 @@ class JobSrv(
128128
): (Source[Artifact, NotUsed], Future[Long]) = {
129129
import org.elastic4play.services.QueryDSL._
130130
withUserFilter(userId) { organizationId =>
131-
findSrv[ArtifactModel, Artifact](
131+
def find(range: Option[String]): (Source[Artifact, NotUsed], Future[Long]) = findSrv[ArtifactModel, Artifact](
132132
artifactModel,
133133
and(queryDef, parent("report", parent("job", and(withId(jobId), "organization" ~= organizationId)))),
134134
range,
135135
sortBy
136136
)
137+
138+
val count = find(Some("0-1"))._2
139+
Source
140+
.futureSource(count.map {
141+
case 0L => Source.empty[Artifact]
142+
case c if range.contains("all") => find(Some(s"0-$c"))._1
143+
case _ => find(range)._1
144+
})
145+
.mapMaterializedValue(_ => NotUsed) -> count
146+
137147
}
138148
}
139149

0 commit comments

Comments
 (0)