def cleanupInactive()

in api/src/main/scala/com/gu/core/store/store.scala [219:241]


  def cleanupInactive(user: User): Either[Error, UserCleaned] = {
    val avatars = for {
      resp <- getAll(user)
    } yield resp.body

    val actives = avatars.map(_.filter(_.isActive)).getOrElse(Nil)
    val inactives = avatars.map(_.filterNot(_.isActive)).getOrElse(Nil)

    if (actives.size > 1) {
      logger.error(s"User ${user.id} has multiple (${actives.size} active avatars")
    }

    if (actives.nonEmpty && inactives.nonEmpty) {
      val buckets = List(incomingBucket, rawBucket, processedBucket)
      val inactiveIDs = inactives.map(_.id)

      for {
        resources <- deleteAvatars(buckets, inactiveIDs)
      } yield UserCleaned(user, resources)
    } else {
      Right(UserCleaned(user, Nil)) // no-op
    }
  }