File tree 1 file changed +11
-20
lines changed
src/main/scala/it/pagopa/interop/purposeprocess/common/readmodel
1 file changed +11
-20
lines changed Original file line number Diff line number Diff line change @@ -162,26 +162,17 @@ object ReadModelPurposeQueries extends ReadModelQuery {
162
162
producersIds : Seq [String ]
163
163
)(implicit ec : ExecutionContext , readModel : ReadModelService ): Future [Bson ] =
164
164
producersIds match {
165
- case Nil => Future .successful(Filters .empty())
166
- case other =>
167
- val producersEservicesIds : Future [Seq [ReadModelId ]] =
168
- mapToVarArgs(other.map(Filters .eq(" data.producerId" , _)))(Filters .or)
169
- .fold[Future [Seq [ReadModelId ]]](Future .successful(Seq .empty))(filter =>
170
- readModel
171
- .find[ReadModelId ](
172
- " eservices" ,
173
- filter,
174
- Projections .include(" data.id" ),
175
- offset = 0 ,
176
- limit = Int .MaxValue
177
- )
178
- )
179
-
180
- producersEservicesIds.map(ids =>
181
- mapToVarArgs(ids.map(id => Filters .eq(" data.eserviceId" , id.id.toString)))(Filters .or)
182
- // Producers have no EServices, we need to force an empty result
183
- .getOrElse(Filters .eq(" field.that.does.not.exist" , " 0" ))
184
- )
165
+ case Nil => Future .successful(Filters .empty())
166
+ case nonEmptyList =>
167
+ readModel
168
+ .find[ReadModelId ](
169
+ " eservices" ,
170
+ Filters .in(" data.producerId" , nonEmptyList : _* ),
171
+ Projections .include(" data.id" ),
172
+ offset = 0 ,
173
+ limit = Int .MaxValue
174
+ )
175
+ .map(eserviceIds => Filters .in(" data.eserviceId" , eserviceIds.map(_.id.toString): _* ))
185
176
}
186
177
187
178
private def purposesEservices (purposes : Seq [PersistentPurpose ], limit : Int )(implicit
You can’t perform that action at this time.
0 commit comments