Skip to content

Commit

Permalink
Merge pull request #1521 from adpi2/fix-1445
Browse files Browse the repository at this point in the history
Fix timeout on getUserState
  • Loading branch information
adpi2 authored Jan 3, 2025
2 parents 3b6724c + 0aaa1b1 commit 03783bf
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,18 @@ object ScalaExtensions {
} yield builder.addOne(b)
}
.map(_.result())

def flatMapSync[B](
f: A => Future[IterableOnce[B]]
)(implicit ec: ExecutionContext, bf: BuildFrom[CC[A], B, CC[B]]): Future[CC[B]] =
in.iterator
.foldLeft(Future.successful(bf.newBuilder(in))) { (builderF, a) =>
for {
builder <- builderF
bs <- f(a)
} yield builder.addAll(bs)
}
.map(_.result())
}

implicit class IteratorExtension[A](iterator: Iterator[A]) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import scala.concurrent.Promise
import scala.concurrent.duration.DurationInt
import scala.util.Try

import cats.implicits.toTraverseOps
import com.typesafe.scalalogging.LazyLogging
import io.circe.Json
import io.circe.syntax._
Expand Down Expand Up @@ -335,9 +334,7 @@ class GithubClientImpl(token: Secret)(implicit val system: ActorSystem)
val permissions = Seq("WRITE", "MAINTAIN", "ADMIN")
for {
organizations <- getUserOrganizations(userInfo.login)
organizationRepos <- organizations.flatTraverse { org =>
getOrganizationRepositories(userInfo.login, org, permissions)
}
organizationRepos <- organizations.flatMapSync(getOrganizationRepositories(userInfo.login, _, permissions))
userRepos <- getUserRepositories(userInfo.login, permissions)
} yield UserState(repos = organizationRepos.toSet ++ userRepos, orgs = organizations.toSet, info = userInfo)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package scaladex.server.route

import java.util.UUID

import scala.util.Failure
import scala.util.Success
import scala.util.Try

Expand Down Expand Up @@ -92,6 +93,10 @@ class AuthenticationApi(clientId: String, sessionConfig: SessionConfig, githubAu
// Update user state lazily
githubAuth.getUserState(token).andThen {
case Success(Some(userState)) => database.updateUser(userId, userState)
case Failure(cause) =>
logger.warn(
s"Failed to update user state of ${user.login} ($userId) because of: ${cause.getMessage}"
)
}

setSession(refreshable, usingCookies, userId)(
Expand Down

0 comments on commit 03783bf

Please sign in to comment.