use http for server to server explorer requests

hyperlinked-message
Thibault Duplessis 2016-06-12 11:14:14 +02:00
parent 1d33d4202e
commit 1d886876c5
3 changed files with 8 additions and 12 deletions

View File

@ -396,10 +396,8 @@ tv {
}
explorer {
endpoint = "https://expl.lichess.org"
internal_endpoint = "http://expl.lichess.org"
index_flow = false
mass_import = {
endpoint = "https://expl.lichess.org"
}
tablebase = {
endpoint = "https://expl.lichess.org/tablebase"
}

View File

@ -9,13 +9,13 @@ final class Env(
system: ActorSystem) {
private val Endpoint = config getString "endpoint"
private val MassImportEndpoint = config getString "mass_import.endpoint"
private val InternalEndpoint = config getString "internal_endpoint"
private val IndexFlow = config getBoolean "index_flow"
private lazy val indexer = new ExplorerIndexer(
gameColl = gameColl,
endpoint = Endpoint,
massImportEndpoint = MassImportEndpoint)
internalEndpoint = InternalEndpoint)
def cli = new lila.common.Cli {
def process = {
@ -26,7 +26,7 @@ final class Env(
def fetchPgn(id: String): Fu[Option[String]] = {
import play.api.libs.ws.WS
import play.api.Play.current
WS.url(s"$Endpoint/master/pgn/$id").get() map {
WS.url(s"$InternalEndpoint/master/pgn/$id").get() map {
case res if res.status == 200 => res.body.some
case _ => None
}

View File

@ -17,8 +17,7 @@ import lila.user.UserRepo
private final class ExplorerIndexer(
gameColl: Coll,
endpoint: String,
massImportEndpoint: String) {
internalEndpoint: String) {
private val maxGames = Int.MaxValue
private val batchSize = 50
@ -28,8 +27,7 @@ private final class ExplorerIndexer(
private val dateFormatter = DateTimeFormat forPattern datePattern
private val dateTimeFormatter = DateTimeFormat forPattern s"$datePattern HH:mm"
private val pgnDateFormat = DateTimeFormat forPattern "yyyy.MM.dd";
private val endPointUrl = s"$endpoint/import/lichess"
private val massImportEndPointUrl = s"$massImportEndpoint/import/lichess"
private val internalEndPointUrl = s"$internalEndpoint/import/lichess"
private def parseDate(str: String): Option[DateTime] =
Try(dateFormatter parseDateTime str).toOption
@ -60,7 +58,7 @@ private final class ExplorerIndexer(
Enumeratee.grouped(Iteratee takeUpTo batchSize) |>>>
Iteratee.foldM[Seq[GamePGN], Long](nowMillis) {
case (millis, pairs) =>
WS.url(massImportEndPointUrl).put(pairs.map(_._2) mkString separator).flatMap {
WS.url(internalEndPointUrl).put(pairs.map(_._2) mkString separator).flatMap {
case res if res.status == 200 =>
val date = pairs.headOption.map(_._1.createdAt) ?? dateTimeFormatter.print
val nb = pairs.size
@ -90,7 +88,7 @@ private final class ExplorerIndexer(
buf += pgn
val startAt = nowMillis
if (buf.size >= max) {
WS.url(endPointUrl).put(buf mkString separator) andThen {
WS.url(internalEndPointUrl).put(buf mkString separator) andThen {
case Success(res) if res.status == 200 =>
lila.mon.explorer.index.time(((nowMillis - startAt) / max).toInt)
lila.mon.explorer.index.success(max)