private[this] def deleteAvatars()

in api/src/main/scala/com/gu/core/store/store.scala [288:307]


  private[this] def deleteAvatars(buckets: Seq[String], ids: List[String]): Either[Error, List[String]] = {
    def delete(ids: List[String]): Either[Error, List[String]] = {
      for {
        locations <- deletePrivateAvatarFiles(buckets, ids)
        _ <- deleteAvatarKvEntries(ids)
      } yield resources(ids, locations)
    }

    val awsBatchLimit = 25
    val groups = ids.sliding(awsBatchLimit)

    // batch as AWS apis can only handle up to 25 items at a time
    val zero: Either[Error, List[String]] = Right(List.empty)
    val rs = groups.foldLeft(zero) {
      case (acc, ids) =>
        acc.flatMap(locations => delete(ids).map(_ ::: locations))
    }

    rs
  }