Skip to content

Commit 9f1e7b3

Browse files
committed
remove duplication
1 parent 56eaaa7 commit 9f1e7b3

2 files changed

Lines changed: 3 additions & 14 deletions

File tree

media-api/app/controllers/MediaApi.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -624,8 +624,8 @@ class MediaApi(
624624
val filteredPoolFilter = buildAiFilter(params)
625625

626626
for {
627-
totalPool <- elasticSearch.countMatchingFilter(basePoolFilter)
628-
filteredPool <- elasticSearch.countMatchingFilter(filteredPoolFilter)
627+
totalPool <- elasticSearch.countMatchingFilterWithExtraCounts(basePoolFilter).map(_._1)
628+
filteredPool <- elasticSearch.countMatchingFilterWithExtraCounts(filteredPoolFilter).map(_._1)
629629
} yield respondCollection(
630630
data = List.empty[EmbeddedEntity[JsValue]],
631631
offset = Some(0),

media-api/app/lib/elasticsearch/ElasticSearch.scala

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ class ElasticSearch(
362362
// How many images match the active filters in total (so we can show
363363
// "Best k of N matches") along with the ticker count badges, both computed
364364
// over the whole filtered set in a single request.
365-
private def countMatchingFilterWithExtraCounts(filterOpt: Option[Query])(implicit ex: ExecutionContext, logMarker: LogMarker): Future[(Long, ExtraCounts)] = {
365+
def countMatchingFilterWithExtraCounts(filterOpt: Option[Query])(implicit ex: ExecutionContext, logMarker: LogMarker): Future[(Long, ExtraCounts)] = {
366366
val searchRequest = ElasticDsl.search(imagesCurrentAlias)
367367
.query(filterOpt.getOrElse(matchAllQuery()))
368368
.trackTotalHits(true)
@@ -374,17 +374,6 @@ class ElasticSearch(
374374
}
375375
}
376376

377-
// How many images match the given filter (or the whole index if no filter),
378-
// used to tell the user the size of the pool an AI search would rank over.
379-
def countMatchingFilter(filterOpt: Option[Query])(implicit ex: ExecutionContext, logMarker: LogMarker): Future[Long] = {
380-
val searchRequest = ElasticDsl.search(imagesCurrentAlias)
381-
.query(filterOpt.getOrElse(matchAllQuery()))
382-
.trackTotalHits(true)
383-
.size(0)
384-
385-
executeAndLog(withSearchQueryTimeout(searchRequest), "AI search filter pool count").map(_.result.totalHits)
386-
}
387-
388377
def search(params: SearchParams)(implicit ex: ExecutionContext, request: AuthenticatedRequest[AnyContent, Principal], logMarker: LogMarker = MarkerMap()): Future[SearchResults] = {
389378
val query: Query = queryBuilder.makeQuery(params.structuredQuery)
390379

0 commit comments

Comments
 (0)