Skip to content

Commit

Permalink
option to index a given number of games
Browse files Browse the repository at this point in the history
  • Loading branch information
ornicar committed Sep 2, 2015
1 parent d29254f commit 636fc18
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
3 changes: 2 additions & 1 deletion modules/gameSearch/src/main/Env.scala
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ final class Env(
import akka.pattern.ask
private implicit def timeout = makeTimeout minutes 60
def process = {
case "game" :: "search" :: "reset" :: Nil => api.reset inject "done"
case "game" :: "search" :: "reset" :: Nil => api.reset(none) inject "done"
case "game" :: "search" :: "reset" :: nb :: Nil => api.reset(parseIntOption(nb)) inject "done"
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions modules/gameSearch/src/main/GameSearchApi.scala
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ final class GameSearchApi(client: ESClient) extends SearchReadApi[Game, Query] {
Fields.blackUser -> game.blackPlayer.userId
).noNull

def reset = client.putMapping >> {
def reset(max: Option[Int]) = client.putMapping >> {
import lila.db.api._
import lila.game.tube.gameTube
var nb = 0
Expand All @@ -58,7 +58,7 @@ final class GameSearchApi(client: ESClient) extends SearchReadApi[Game, Query] {
for {
size <- $count($select.all)
batchSize = 2000
limit = Int.MaxValue
limit = max | Int.MaxValue
_ <- $enumerate.bulk[Option[Game]]($query.all, batchSize, limit) { gameOptions =>
val games = gameOptions.flatten filter storable
val nbGames = games.size
Expand All @@ -72,7 +72,7 @@ final class GameSearchApi(client: ESClient) extends SearchReadApi[Game, Query] {
nbSkipped = nbSkipped + gameOptions.size - nbGames
val perS = (batchSize * 1000) / math.max(1, (nowMillis - started))
started = nowMillis
loginfo("[game search] Indexed %d of %d, skipped %d, at %d/s".format(nb, size, nbSkipped, perS))
loginfo("[game search] Indexed %d of %d, skipped %d, at %d/s".format(nb + nbSkipped, size, nbSkipped, perS))
}
}
} yield ()
Expand Down

0 comments on commit 636fc18

Please sign in to comment.