Skip to content

Commit

Permalink
delete more dead code
Browse files Browse the repository at this point in the history
  • Loading branch information
ornicar committed Jan 15, 2017
1 parent ee1e881 commit 1d442a9
Show file tree
Hide file tree
Showing 59 changed files with 35 additions and 183 deletions.
1 change: 0 additions & 1 deletion app/controllers/Account.scala
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,6 @@ object Account extends LilaController {

def kidConfirm = Auth { ctx =>
me =>
implicit val req = ctx.req
(UserRepo toggleKid me) inject Redirect(routes.Account.kid)
}

Expand Down
2 changes: 0 additions & 2 deletions app/controllers/Analyse.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import views._
object Analyse extends LilaController {

private def env = Env.analyse
private def bookmarkApi = Env.bookmark.api
private val divider = Env.game.divider

def requestAnalysis(id: String) = Auth { implicit ctx => me =>
OptionFuResult(GameRepo game id) { game =>
Expand Down
25 changes: 12 additions & 13 deletions app/controllers/Api.scala
Original file line number Diff line number Diff line change
Expand Up @@ -65,19 +65,19 @@ object Api extends LilaController {
}
}

private val GamesRateLimitPerIP = new lila.memo.RateLimit(
private val UserGamesRateLimitPerIP = new lila.memo.RateLimit(
credits = 10 * 1000,
duration = 10 minutes,
name = "user games API per IP",
key = "user_games.api.ip")

private val GamesRateLimitPerUA = new lila.memo.RateLimit(
private val UserGamesRateLimitPerUA = new lila.memo.RateLimit(
credits = 10 * 1000,
duration = 5 minutes,
name = "user games API per UA",
key = "user_games.api.ua")

private val GamesRateLimitGlobal = new lila.memo.RateLimit(
private val UserGamesRateLimitGlobal = new lila.memo.RateLimit(
credits = 10 * 1000,
duration = 1 minute,
name = "user games API global",
Expand All @@ -88,9 +88,9 @@ object Api extends LilaController {
val nb = (getInt("nb") | 10) atLeast 1 atMost 100
val cost = page * nb + 10
val ip = HTTPRequest lastRemoteAddress ctx.req
GamesRateLimitPerIP(ip, cost = cost) {
GamesRateLimitPerUA(~HTTPRequest.userAgent(ctx.req), cost = cost, msg = ip) {
GamesRateLimitGlobal("-", cost = cost, msg = ip) {
UserGamesRateLimitPerIP(ip, cost = cost) {
UserGamesRateLimitPerUA(~HTTPRequest.userAgent(ctx.req), cost = cost, msg = ip) {
UserGamesRateLimitGlobal("-", cost = cost, msg = ip) {
lila.mon.api.userGames.cost(cost)
lila.user.UserRepo named name flatMap {
_ ?? { user =>
Expand All @@ -114,16 +114,15 @@ object Api extends LilaController {
}
}

private val GameRateLimitPerIdAndIP = new lila.memo.RateLimit(
credits = 5,
duration = 3 minutes,
name = "game API per Id/IP",
key = "game.api.id_ip")
private val GameRateLimitPerIP = new lila.memo.RateLimit(
credits = 100,
duration = 1 minute,
name = "game API per IP",
key = "game.api.one.ip")

def game(id: String) = ApiRequest { implicit ctx =>
val ip = HTTPRequest lastRemoteAddress ctx.req
val key = s"$id:$ip"
GamesRateLimitPerIP(key, cost = 1) {
GameRateLimitPerIP(ip, cost = 1) {
lila.mon.api.game.cost(1)
gameApi.one(
id = id take lila.game.Game.gameIdSize,
Expand Down
4 changes: 0 additions & 4 deletions app/controllers/Auth.scala
Original file line number Diff line number Diff line change
Expand Up @@ -171,10 +171,6 @@ object Auth extends LilaController {
} recoverWith authRecovery
}

private def noTorResponse(implicit ctx: Context) = negotiate(
html = Unauthorized(html.auth.tor()).fuccess,
api = _ => Unauthorized(jsonError("Can't login from Tor, sorry!")).fuccess)

def setFingerprint(fp: String, ms: Int) = Auth { ctx => me =>
api.setFingerprint(ctx.req, fp) flatMap {
_ ?? { hash =>
Expand Down
1 change: 0 additions & 1 deletion app/controllers/Coach.scala
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ object Coach extends LilaController {
def pictureApply = AuthBody(BodyParsers.parse.multipartFormData) { implicit ctx =>
me =>
OptionFuResult(api findOrInit me) { c =>
implicit val req = ctx.body
ctx.body.body.file("picture") match {
case Some(pic) => api.uploadPicture(c, pic) recover {
case e: lila.common.LilaException => BadRequest(html.coach.picture(c, e.message.some))
Expand Down
2 changes: 0 additions & 2 deletions app/controllers/Game.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import views._

object Game extends LilaController {

private def cached = Env.game.cached

def delete(gameId: String) = Auth { implicit ctx =>
me =>
OptionFuResult(GameRepo game gameId) { game =>
Expand Down
9 changes: 0 additions & 9 deletions app/controllers/Insight.scala
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,4 @@ object Insight extends LilaController {
}
}
}

private def AccessibleJson(username: String)(f: lila.user.User => Fu[Result])(implicit ctx: Context) =
lila.user.UserRepo named username flatMap {
_.fold(notFoundJson(s"No such user: $username")) { u =>
env.share.grant(u, ctx.me) flatMap {
_.fold(f(u), fuccess(Forbidden(jsonError(s"User $username data is protected"))))
}
}
} map (_ as JSON)
}
6 changes: 2 additions & 4 deletions app/controllers/Puzzle.scala
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,7 @@ object Puzzle extends LilaController {
val result = Result(resultInt == 1)
ctx.me match {
case Some(me) => for {
finished <- env.finisher(puzzle, me, result)
(round, mode) = finished
(round, mode) <- env.finisher(puzzle, me, result)
me2 <- mode.rated.fold(UserRepo byId me.id map (_ | me), fuccess(me))
infos <- env userInfos me2
voted <- ctx.me.?? { env.api.vote.value(puzzle.id, _) }
Expand Down Expand Up @@ -129,8 +128,7 @@ object Puzzle extends LilaController {
err => fuccess(BadRequest(errorsAsJson(err))),
resultInt => ctx.me match {
case Some(me) => for {
finished <- env.finisher(puzzle, me, Result(resultInt == 1))
(round, mode) = finished
(round, mode) <- env.finisher(puzzle, me, Result(resultInt == 1))
me2 <- mode.rated.fold(UserRepo byId me.id map (_ | me), fuccess(me))
infos <- env userInfos me2
voted <- ctx.me.?? { env.api.vote.value(puzzle.id, _) }
Expand Down
1 change: 0 additions & 1 deletion app/controllers/Round.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import views._
object Round extends LilaController with TheftPrevention {

private def env = Env.round
private def bookmarkApi = Env.bookmark.api
private def analyser = Env.analyse.analyser

def websocketWatcher(gameId: String, color: String) = SocketOption[JsValue] { implicit ctx =>
Expand Down
1 change: 0 additions & 1 deletion app/controllers/Search.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import views._

object Search extends LilaController {

private def paginator = Env.game.paginator
private def env = Env.gameSearch
def searchForm = env.forms.search

Expand Down
1 change: 0 additions & 1 deletion app/controllers/Tv.scala
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ object Tv extends LilaController {
import akka.pattern.ask
import lila.round.TvBroadcast
import play.api.libs.EventSource
implicit val encoder = play.api.libs.Comet.CometMessage.jsonMessages
Env.round.tvBroadcast ? TvBroadcast.GetEnumerator mapTo
manifest[TvBroadcast.EnumeratorType] map { enum =>
Ok.chunked(enum &> EventSource()).as("text/event-stream")
Expand Down
4 changes: 0 additions & 4 deletions app/controllers/User.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,7 @@ import views._
object User extends LilaController {

private def env = Env.user
private def gamePaginator = Env.game.paginator
private def forms = lila.user.DataForm
private def relationApi = Env.relation.api
private def ratingChartApi = Env.history.ratingChartApi
private def userGameSearch = Env.gameSearch.userGameSearch

def tv(username: String) = Open { implicit ctx =>
Expand Down Expand Up @@ -69,7 +66,6 @@ object User extends LilaController {

def online = Open { implicit req =>
val max = 50
def get(nb: Int) = UserRepo.byIdsSortRating(env.onlineUserIdMemo.keys, nb)
negotiate(
html = notFound,
api = _ => env.cached top50Online true map { list =>
Expand Down
2 changes: 0 additions & 2 deletions app/mashup/GameFilter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ object GameFilterMenu {
me: Option[User],
currentNameOption: Option[String]): GameFilterMenu = {

val user = info.user

val filters = NonEmptyList.nel(All, List(
(info.nbWithMe > 0) option Me,
(info.nbRated > 0) option Rated,
Expand Down
4 changes: 2 additions & 2 deletions app/templating/GameHelper.scala
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ trait GameHelper { self: I18nHelper with UserHelper with AiHelper with StringHel
withLink: Boolean = true,
withLive: Boolean = true)(implicit ctx: UserContext) = Html {
val game = pov.game
var isLive = withLive && game.isBeingPlayed
val isLive = withLive && game.isBeingPlayed
val href = withLink ?? s"""href="${gameLink(game, pov.color, ownerLink, tv)}""""
val title = withTitle ?? s"""title="${gameTitle(game, pov.color)}""""
val cssClass = isLive ?? ("live live_" + game.id)
Expand All @@ -223,7 +223,7 @@ trait GameHelper { self: I18nHelper with UserHelper with AiHelper with StringHel
}

def gameFenNoCtx(pov: Pov, tv: Boolean = false, blank: Boolean = false) = Html {
var isLive = pov.game.isBeingPlayed
val isLive = pov.game.isBeingPlayed
val variant = pov.game.variant.key
s"""<a href="%s%s" title="%s" class="mini_board mini_board_${pov.game.id} parse_fen is2d %s $variant" data-live="%s" data-color="%s" data-fen="%s" data-lastmove="%s"%s>$miniBoardContent</a>""".format(
blank ?? netBaseUrl,
Expand Down
5 changes: 0 additions & 5 deletions app/templating/I18hHelper.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ import lila.user.UserContext
trait I18nHelper {

private def pool = i18nEnv.pool
private def transInfos = i18nEnv.transInfos
private def hideCallsCookieName = i18nEnv.hideCallsCookieName

lazy val trans = i18nEnv.keys
lazy val protocol = i18nEnv.RequestHandlerProtocol
Expand Down Expand Up @@ -62,7 +60,4 @@ trait I18nHelper {
ctx.req.acceptLanguages exists (_.language == lang.language)

private val uriPlaceholder = "[URI]"

private def langUrl(lang: Lang)(i18nDomain: I18nDomain) =
protocol + (i18nDomain withLang lang).domain + uriPlaceholder
}
15 changes: 6 additions & 9 deletions app/templating/UserHelper.scala
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,12 @@ trait UserHelper { self: I18nHelper with StringHelper with NumberHelper =>
userId: String,
username: String,
isPatron: Boolean,
cssClass: Option[String] = None,
withOnline: Boolean = true,
withTitle: Boolean = true,
truncate: Option[Int] = None,
title: Option[String] = None,
params: String = ""): String = {
cssClass: Option[String],
withOnline: Boolean,
withTitle: Boolean,
truncate: Option[Int],
title: Option[String],
params: String): String = {
val klass = userClass(userId, cssClass, withOnline)
val href = userHref(username, params = params)
val content = truncate.fold(username)(username.take)
Expand Down Expand Up @@ -262,13 +262,10 @@ trait UserHelper { self: I18nHelper with StringHelper with NumberHelper =>
val patronIconChar = ""
val lineIconChar = ""

private val donorBadge = """<i data-icon="&#xe001;" class="donor is-gold" title="Lichess donor"></i>"""

val lineIcon: String = s"""<i class="line"></i>"""
val patronIcon: String = s"""<i class="line patron" title="lichess Patron"></i>"""
private def lineIcon(patron: Boolean): String = if (patron) patronIcon else lineIcon
private def lineIcon(user: Option[LightUser]): String = lineIcon(user.??(_.isPatron))
private def lineIcon(user: LightUser): String = lineIcon(user.isPatron)
def lineIcon(user: User): String = lineIcon(user.isPatron)
def lineIconChar(user: User): String = if (user.isPatron) patronIconChar else lineIconChar
}
8 changes: 0 additions & 8 deletions conf/base.conf
Original file line number Diff line number Diff line change
Expand Up @@ -225,9 +225,6 @@ analyse {
collection.analysis = analysis2
collection.requester = analysis_requester
net.domain = ${net.domain}
cached.nb.ttl = ${game.cached.nb.ttl}
paginator.max_per_page = ${game.paginator.max_per_page}
actor.name = analyser
}
geoip {
file = ""
Expand Down Expand Up @@ -381,10 +378,6 @@ game {
game = game5
crosstable = crosstable2
}
js_path {
raw = public/javascripts/big.js
compiled = public/compiled/big.js
}
captcher {
name = captcher
duration = 7 seconds
Expand Down Expand Up @@ -526,7 +519,6 @@ memo {
}
}
setup {
friend.memo.ttl = 1 day
casual_only = ${app.casual_only}
collection {
user_config = config
Expand Down
3 changes: 0 additions & 3 deletions modules/analyse/src/main/Env.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ final class Env(
private val CollectionAnalysis = config getString "collection.analysis"
private val CollectionRequester = config getString "collection.requester"
private val NetDomain = config getString "net.domain"
private val CachedNbTtl = config duration "cached.nb.ttl"
private val PaginatorMaxPerPage = config getInt "paginator.max_per_page"
private val ActorName = config getString "actor.name"

lazy val analysisColl = db(CollectionAnalysis)

Expand Down
2 changes: 1 addition & 1 deletion modules/blog/src/main/ProtocolFix.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ object ProtocolFix {
def remove(html: String) = RemoveRegex.replaceAllIn(html, _ => "//lichess.org")

private val AddRegex = """(https?:)?(//)?(\w{2}\.)?lichess\.org""".r
def add(html: String) = RemoveRegex.replaceAllIn(html, _ => "https://lichess.org")
def add(html: String) = AddRegex.replaceAllIn(html, _ => "https://lichess.org")
}
2 changes: 1 addition & 1 deletion modules/challenge/src/main/ChallengeRepo.scala
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ private final class ChallengeRepo(coll: Coll, maxPerUser: Int) {
private def setStatus(
challenge: Challenge,
status: Status,
expiresAt: Option[DateTime => DateTime] = None) = coll.update(
expiresAt: Option[DateTime => DateTime]) = coll.update(
selectCreated ++ $id(challenge.id),
$doc("$set" -> $doc(
"status" -> status.id,
Expand Down
1 change: 0 additions & 1 deletion modules/explorer/src/main/Env.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ final class Env(
gameColl: lila.db.dsl.Coll,
system: ActorSystem) {

private val Endpoint = config getString "endpoint"
private val InternalEndpoint = config getString "internal_endpoint"
private val IndexFlow = config getBoolean "index_flow"

Expand Down
3 changes: 0 additions & 3 deletions modules/fishnet/src/main/Cleaner.scala
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,6 @@ private final class Cleaner(
}.sequenceFu.void
}

private def scheduleMoves = scheduler.once(1 second)(cleanMoves)
private def scheduleAnalysis = scheduler.once(5 second)(cleanAnalysis)

scheduler.effect(3 seconds, "fishnet clean moves")(cleanMoves)
scheduler.effect(10 seconds, "fishnet clean analysis")(cleanAnalysis)
}
1 change: 0 additions & 1 deletion modules/fishnet/src/main/MoveDB.scala
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ private final class MoveDB(

def clean = actor ? Clean mapTo manifest[Iterable[Move]]

private object GetSize
private object Mon
private object Clean
private case class Add(move: Move)
Expand Down
2 changes: 0 additions & 2 deletions modules/forum/src/main/Env.scala
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,6 @@ final class Env(

object Env {

private def hub = lila.hub.Env.current

lazy val current = "forum" boot new Env(
config = lila.common.PlayApp loadConfig "forum",
db = lila.db.Env.current,
Expand Down
3 changes: 0 additions & 3 deletions modules/game/src/main/CrosstableApi.scala
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,6 @@ final class CrosstableApi(
case _ => funit
}

private def exists(u1: String, u2: String) =
coll.exists(select(u1, u2))

private def createFast(u1: String, u2: String) =
creationCache(u1 -> u2).withTimeoutDefault(1 second, none)(system)

Expand Down
5 changes: 0 additions & 5 deletions modules/game/src/main/Env.scala
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ final class Env(
val CaptcherDuration = config duration "captcher.duration"
val CollectionGame = config getString "collection.game"
val CollectionCrosstable = config getString "collection.crosstable"
val JsPathRaw = config getString "js_path.raw"
val JsPathCompiled = config getString "js_path.compiled"
val UciMemoTtl = config duration "uci_memo.ttl"
val netBaseUrl = config getString "net.base_url"
val PngUrl = config getString "png.url"
Expand Down Expand Up @@ -85,9 +83,6 @@ final class Env(
}

lazy val stream = new GameStream(system)

private def jsPath =
"%s/%s".format(appPath, isProd.fold(JsPathCompiled, JsPathRaw))
}

object Env {
Expand Down
2 changes: 1 addition & 1 deletion modules/game/src/main/UciMemo.scala
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ final class UciMemo(ttl: Duration) {
memo.put(game.id, current.take(current.size - nb))
}

private def compute(game: Game, max: Int = hardLimit): Fu[Vector[String]] = for {
private def compute(game: Game, max: Int): Fu[Vector[String]] = for {
fen GameRepo initialFen game
uciMoves UciDump(game.pgnMoves.take(max), fen, game.variant).future
} yield uciMoves.toVector
Expand Down
3 changes: 0 additions & 3 deletions modules/gameSearch/src/main/DataForm.scala
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,6 @@ private[gameSearch] case class SearchData(
case DateDelta(n, "y") => parseIntOption(n) map DateTime.now.minusYears
case _ => None
}
private val dateConstraint = Constraints.pattern(
regex = DateDelta,
error = "Invalid date.")
}

private[gameSearch] case class SearchPlayer(
Expand Down
Loading

0 comments on commit 1d442a9

Please sign in to comment.