more tournament join optimization
This commit is contained in:
parent
95fff08b50
commit
b6f28e46f1
|
@ -206,12 +206,18 @@ final class PlayerRepo(coll: Coll)(implicit ec: scala.concurrent.ExecutionContex
|
||||||
coll.update.one(selectId(player._id), player).void
|
coll.update.one(selectId(player._id), player).void
|
||||||
}
|
}
|
||||||
|
|
||||||
def join(tourId: Tournament.ID, user: User, perfType: PerfType, team: Option[TeamID]) =
|
def join(
|
||||||
find(tourId, user.id) flatMap {
|
tourId: Tournament.ID,
|
||||||
|
user: User,
|
||||||
|
perfType: PerfType,
|
||||||
|
team: Option[TeamID],
|
||||||
|
prev: Option[Player]
|
||||||
|
) =
|
||||||
|
prev match {
|
||||||
case Some(p) if p.withdraw => coll.update.one(selectId(p._id), $unset("w"))
|
case Some(p) if p.withdraw => coll.update.one(selectId(p._id), $unset("w"))
|
||||||
case Some(_) => funit
|
case Some(_) => funit
|
||||||
case None => coll.insert.one(Player.make(tourId, user, perfType, team))
|
case None => coll.insert.one(Player.make(tourId, user, perfType, team))
|
||||||
} void
|
}
|
||||||
|
|
||||||
def withdraw(tourId: Tournament.ID, userId: User.ID) =
|
def withdraw(tourId: Tournament.ID, userId: User.ID) =
|
||||||
coll.update.one(selectTourUser(tourId, userId), $set("w" -> true)).void
|
coll.update.one(selectTourUser(tourId, userId), $set("w" -> true)).void
|
||||||
|
|
|
@ -289,25 +289,26 @@ final class TournamentApi(
|
||||||
promise: Option[Promise[Tournament.JoinResult]]
|
promise: Option[Promise[Tournament.JoinResult]]
|
||||||
): Funit =
|
): Funit =
|
||||||
Sequencing(tourId)(tournamentRepo.enterableById) { tour =>
|
Sequencing(tourId)(tournamentRepo.enterableById) { tour =>
|
||||||
playerRepo.exists(tour.id, me.id) flatMap { playerExists =>
|
playerRepo.find(tour.id, me.id) flatMap { prevPlayer =>
|
||||||
import Tournament.JoinResult
|
import Tournament.JoinResult
|
||||||
val fuResult: Fu[JoinResult] =
|
val fuResult: Fu[JoinResult] =
|
||||||
if (!playerExists && tour.password.exists(p => !password.has(p))) fuccess(JoinResult.WrongEntryCode)
|
if (prevPlayer.isEmpty && tour.password.exists(p => !password.has(p)))
|
||||||
|
fuccess(JoinResult.WrongEntryCode)
|
||||||
else
|
else
|
||||||
getVerdicts(tour, me.some, getUserTeamIds, playerExists) flatMap { verdicts =>
|
getVerdicts(tour, me.some, getUserTeamIds, prevPlayer.isDefined) flatMap { verdicts =>
|
||||||
if (!verdicts.accepted) fuccess(JoinResult.Verdicts)
|
if (!verdicts.accepted) fuccess(JoinResult.Verdicts)
|
||||||
else if (!pause.canJoin(me.id, tour)) fuccess(JoinResult.Paused)
|
else if (!pause.canJoin(me.id, tour)) fuccess(JoinResult.Paused)
|
||||||
else {
|
else {
|
||||||
def proceedWithTeam(team: Option[String]): Fu[JoinResult] =
|
def proceedWithTeam(team: Option[String]): Fu[JoinResult] =
|
||||||
playerRepo.join(tour.id, me, tour.perfType, team) >>
|
playerRepo.join(tour.id, me, tour.perfType, team, prevPlayer) >>
|
||||||
updateNbPlayers(tour.id) >>- {
|
updateNbPlayers(tour.id) >>- {
|
||||||
socket.reload(tour.id)
|
socket.reload(tour.id)
|
||||||
publish()
|
publish()
|
||||||
} inject JoinResult.Ok
|
} inject JoinResult.Ok
|
||||||
withTeamId match {
|
withTeamId match {
|
||||||
case None if tour.isTeamBattle && playerExists => proceedWithTeam(none)
|
case None if tour.isTeamBattle && prevPlayer.isDefined => proceedWithTeam(none)
|
||||||
case None if tour.isTeamBattle => fuccess(JoinResult.MissingTeam)
|
case None if tour.isTeamBattle => fuccess(JoinResult.MissingTeam)
|
||||||
case None => proceedWithTeam(none)
|
case None => proceedWithTeam(none)
|
||||||
case Some(team) =>
|
case Some(team) =>
|
||||||
tour.teamBattle match {
|
tour.teamBattle match {
|
||||||
case Some(battle) if battle.teams contains team =>
|
case Some(battle) if battle.teams contains team =>
|
||||||
|
|
Loading…
Reference in a new issue