Skip to content

Commit 3599492

Browse files
authored
Merge branch 'master' into relay-vertical-resizer-fix
2 parents 00993f3 + 59f9924 commit 3599492

File tree

18 files changed

+97
-69
lines changed

18 files changed

+97
-69
lines changed

app/controllers/Streamer.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ final class Streamer(env: Env, apiC: => Api) extends LilaController(env):
229229
def oauthLinkYoutube = Auth { _ ?=> _ ?=>
230230
Found(myStreamer): _ =>
231231
val state = oauth.makeState()
232-
val redirectUri = routeUrl(routes.Streamer.oauthYoutubeRedirect).pp
232+
val redirectUri = routeUrl(routes.Streamer.oauthYoutubeRedirect)
233233
val url = oauth.authorizeUrl.youtube(redirectUri, state, getBool("force_verify"))
234234
Redirect(url).withCookies(oauthMakeCookie("youtube", state))
235235
}

build.sbt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ lazy val history = module("history",
205205
)
206206

207207
lazy val search = module("search",
208-
Seq(common),
208+
Seq(memo),
209209
Seq(playWs.ahc, lilaSearch)
210210
)
211211

modules/common/src/main/MarkdownRender.scala

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,11 @@ final class MarkdownRender(
9393

9494
// https://github.com/vsch/flexmark-java/issues/496
9595
private val tooManyUnderscoreRegex = """(_{6,})""".r
96-
private def preventStackOverflow(text: Markdown) = Markdown:
97-
tooManyUnderscoreRegex.replaceAllIn(text.value, "_" * 3)
96+
private val tooManyQuotes = """^[>\s*]{5,}""".r
97+
private def preventStackOverflow(text: Markdown) =
98+
text.map:
99+
_.pipe(tooManyUnderscoreRegex.replaceAllIn(_, "_" * 3))
100+
.pipe(tooManyQuotes.replaceAllIn(_, ">" * 4))
98101

99102
def apply(key: MarkdownRender.Key)(text: Markdown): Html = Html:
100103
Chronometer

modules/coreI18n/src/main/i18n.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ trait LangPicker:
5959
def preferedLanguages(req: RequestHeader, prefLang: Lang): List[Language]
6060
def byStrOrDefault(str: Option[String]): Lang
6161

62+
// play's req.acceptLanguages can throw exceptions if request headers are malformed
63+
def playAcceptLanguages(req: RequestHeader): Seq[Lang] =
64+
scala.util.Try(req.acceptLanguages).toOption.getOrElse(Seq.empty)
65+
6266
trait JsDump:
6367
def keysToObject(keys: Seq[I18nKey])(using Translate): play.api.libs.json.JsObject
6468

modules/i18n/src/main/LangPicker.scala

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,13 @@ import play.api.i18n.Lang
44
import play.api.mvc.RequestHeader
55
import scalalib.model.{ Language, LangTag }
66

7-
import lila.core.i18n.{ toLanguage, defaultLang, defaultLanguage, fixJavaLanguage }
7+
import lila.core.i18n.{
8+
toLanguage,
9+
defaultLang,
10+
defaultLanguage,
11+
fixJavaLanguage,
12+
playAcceptLanguages as acceptLanguages
13+
}
814

915
object LangPicker extends lila.core.i18n.LangPicker:
1016

@@ -17,11 +23,11 @@ object LangPicker extends lila.core.i18n.LangPicker:
1723
.getOrElse(defaultLang)
1824

1925
def bestFromRequestHeaders(req: RequestHeader): Option[Lang] =
20-
req.acceptLanguages.collectFirstSome(findCloser)
26+
acceptLanguages(req).collectFirstSome(findCloser)
2127

2228
def allFromRequestHeaders(req: RequestHeader): List[Lang] = {
23-
req.acceptLanguages.flatMap(findCloser) ++
24-
req.acceptLanguages.flatMap(lang => ~byCountry.get(lang.country))
29+
acceptLanguages(req).flatMap(findCloser) ++
30+
acceptLanguages(req).flatMap(lang => ~byCountry.get(lang.country))
2531
}.distinct.toList
2632

2733
def byStr(str: String): Option[Lang] =
@@ -35,7 +41,7 @@ object LangPicker extends lila.core.i18n.LangPicker:
3541
langs.sortBy { mine.getOrElse(_, Int.MaxValue) }
3642

3743
def preferedLanguages(req: RequestHeader, prefLang: Lang): List[Language] = {
38-
toLanguage(prefLang) +: req.acceptLanguages.map(toLanguage)
44+
toLanguage(prefLang) +: acceptLanguages(req).map(toLanguage)
3945
}.distinct.view.filter(LangList.popularLanguages.contains).toList
4046

4147
def pickBestOf(
@@ -46,7 +52,7 @@ object LangPicker extends lila.core.i18n.LangPicker:
4652
.map(toLanguage)
4753
.filter(candidates.contains)
4854
.orElse:
49-
req.acceptLanguages
55+
acceptLanguages(req)
5056
.map(toLanguage)
5157
.collectFirst:
5258
case l if candidates.contains(l) => l
@@ -66,9 +72,10 @@ object LangPicker extends lila.core.i18n.LangPicker:
6672
else defaultByLanguage.get(to.language).orElse(lichessCodes.get(to.language))
6773

6874
def byHref(language: Language, req: RequestHeader): ByHref =
75+
val accepted = acceptLanguages(req)
6976
Lang.get(language.value).flatMap(findCloser) match
7077
case Some(lang) if fixJavaLanguage(lang) == language =>
71-
if req.acceptLanguages.isEmpty || req.acceptLanguages.exists(_.language == lang.language)
78+
if accepted.isEmpty || accepted.exists(_.language == lang.language)
7279
then ByHref.Found(lang)
7380
else ByHref.Refused(lang)
7481
case Some(lang) => ByHref.Redir(fixJavaLanguage(lang))

modules/recap/src/main/ui/RecapUi.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,6 @@ final class RecapUi(helpers: Helpers):
2828
main(cls := "page-small box box-pad page")(
2929
h1(cls := "box__top")(s"Lichess Recap $year will be available soon."),
3030
div(
31-
p("Check back later!")
31+
p("Check back at the end of the year!")
3232
)
3333
)

modules/relay/src/main/RelayHome.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ final class RelayHomeApi(listing: RelayListing, pager: RelayPager, jsonView: Rel
1414
active <- listing.active
1515
past <- pager.inactive(1)
1616
(recent, reallyPast) = stealRecentFromPast(past.currentPageResults)
17-
yield RelayHome(active, recent.pp, past.withCurrentPageResults(reallyPast))
17+
yield RelayHome(active, recent, past.withCurrentPageResults(reallyPast))
1818

1919
def get(page: Int): Fu[RelayHome | Paginator[WithLastRound]] =
2020
if page == 1 then home

modules/search/src/main/Env.scala

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,13 @@ private class SearchConfig(val enabled: Boolean, val endpoint: String)
1313
@Module
1414
final class Env(
1515
appConfig: Configuration,
16-
ws: StandaloneWSClient
16+
ws: StandaloneWSClient,
17+
cacheApi: lila.memo.CacheApi
1718
)(using Executor):
1819

1920
private val config = appConfig.get[SearchConfig]("search")(using AutoConfig.loader)
2021

2122
val client: SearchClient =
2223
val _client =
2324
if config.enabled then SearchClient.play(ws, s"${config.endpoint}/api") else SearchClient.noop
24-
LilaSearchClient(_client)
25+
LilaSearchClient(_client, cacheApi)

modules/search/src/main/LilaSearchClient.scala

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,21 @@ package lila.search
33
import lila.search.client.SearchClient
44
import lila.search.spec.*
55

6-
class LilaSearchClient(client: SearchClient)(using Executor) extends SearchClient:
6+
class LilaSearchClient(client: SearchClient, cacheApi: lila.memo.CacheApi)(using Executor)
7+
extends SearchClient:
8+
9+
private val cache = cacheApi[Query, CountOutput](1024, "search.count"):
10+
_.expireAfterWrite(2.minutes).buildAsyncFuture: query =>
11+
monitor("count", query.index):
12+
client
13+
.count(query)
14+
.handleError:
15+
case e =>
16+
logger.info(s"Count error: query={$query}", e)
17+
CountOutput(0)
718

819
override def count(query: Query): Future[CountOutput] =
9-
monitor("count", query.index):
10-
client
11-
.count(query)
12-
.handleError:
13-
case e =>
14-
logger.info(s"Count error: query={$query}", e)
15-
CountOutput(0)
20+
cache.get(query)
1621

1722
override def search(query: Query, from: From, size: Size): Future[SearchOutput] =
1823
monitor("search", query.index):

modules/study/src/main/ui/ListUi.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ final class ListUi(helpers: Helpers, bits: StudyBits):
108108
bits.orderSelect(order, "search", url = o => routes.Study.search(text, 1, o.some)),
109109
bits.newForm()
110110
),
111-
paginate(pag, routes.Study.search(text, pag.currentPage, order.some))
111+
paginate(pag, routes.Study.search(text, 1, order.some))
112112
)
113113
)
114114

0 commit comments

Comments
 (0)