Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions common/app/renderers/DotcomRenderingService.scala
Original file line number Diff line number Diff line change
Expand Up @@ -490,15 +490,17 @@ class DotcomRenderingService extends GuLogging with ResultWithPreconnectPreload
def getFootballMatchSummaryPage(
ws: WSClient,
json: JsValue,
cacheTime: CacheTime,
)(implicit request: RequestHeader): Future[Result] = {
post(ws, json, Configuration.rendering.articleBaseURL + "/FootballMatchSummaryPage", CacheTime.FootballMatch)
post(ws, json, Configuration.rendering.articleBaseURL + "/FootballMatchSummaryPage", cacheTime)
}

def getAppsFootballMatchSummaryPage(
ws: WSClient,
json: JsValue,
cacheTime: CacheTime,
)(implicit request: RequestHeader): Future[Result] = {
post(ws, json, Configuration.rendering.articleBaseURL + "/AppsFootballMatchSummaryPage", CacheTime.FootballMatch)
post(ws, json, Configuration.rendering.articleBaseURL + "/AppsFootballMatchSummaryPage", cacheTime)
}

def getCricketPage(
Expand Down
6 changes: 6 additions & 0 deletions sport/app/football/controllers/MatchController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ class MatchController(
val page: Future[MatchPage] = lineup.map(MatchPage(theMatch, _))
val tier = FootballSummaryPagePicker.getTier()

val cacheTime =
if (theMatch.isAboutToStart || theMatch.isLive) CacheTime(10) else CacheTime(300)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering how the new cache time values align with the current cache time settings in Cached.scala e.g.

object Football extends CacheTime(10)
object FootballMatch extends CacheTime(30)

Would it be possible to use (or create) constants in Cached.scala so all the cache time values are in one place?


page.flatMap { page =>
val matchStats = MatchStats.statsFromFootballMatch(theMatch, page.lineUp, theMatch.matchStatus)

Expand Down Expand Up @@ -121,9 +124,11 @@ class MatchController(
group = group,
competitionName = competitionSummary.fullName,
)

remoteRenderer.getFootballMatchSummaryPage(
wsClient,
DotcomRenderingFootballMatchSummaryDataModel.toJson(model),
cacheTime,
)

case AppsFormat if tier == RemoteRender =>
Expand All @@ -137,6 +142,7 @@ class MatchController(
remoteRenderer.getAppsFootballMatchSummaryPage(
wsClient,
DotcomRenderingFootballMatchSummaryDataModel.toJson(model),
cacheTime,
)

case _ =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ class MoreOnMatchController(
competitionSummary,
filtered,
)
Cached(if (theMatch.isLive) 10 else 300)(JsonComponent.fromWritable(model))
Cached(if (theMatch.isAboutToStart || theMatch.isLive) 10 else 300)(JsonComponent.fromWritable(model))
}
}
maybeResponse.getOrElse(Future.successful(Cached(30) { JsonNotFound() }))
Expand Down
7 changes: 7 additions & 0 deletions sport/app/football/implicits/Football.scala
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@ trait Football {

def isOn(date: LocalDate): Boolean = m.date.toLocalDate == date

def isAboutToStart: Boolean = {
val now = ZonedDateTime.now()
val upperBound = now.plusMinutes(5)

m.date.isAfter(now) && m.date.isBefore(upperBound)
}

// results and fixtures do not actually have a status field in the API
lazy val matchStatus = m match {
case f: Fixture => "Fixture"
Expand Down
22 changes: 22 additions & 0 deletions sport/test/football/implicits/FootballTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,27 @@ class FootballTest extends AnyFeatureSpec with GivenWhenThen with Matchers with
val isMatchOnToday = todayMatch.isOn(today.toLocalDate)
isMatchOnToday shouldBe (true)
}

Scenario("isAboutToStart returns true if match start time is within the next 5 minutes") {

Given("a match which happens in 5 minutes")
val fiveMinutesFromNow = ZonedDateTime.now().plusMinutes(5)
val theMatch =
liveMatch("Aston Villa", "Cardiff", 1, 0, fiveMinutesFromNow, isLive = true)

Then("calling isAboutToStart should return true")
theMatch.isAboutToStart shouldBe (true)
}

Scenario("isAboutToStart returns false if match start time is more than 5 minutes from now") {

Given("a match starting in more than 5 minutes")
val fiveMinutesFromNow = ZonedDateTime.now().plusMinutes(5).plusSeconds(1)
val theMatch =
liveMatch("Aston Villa", "Cardiff", 1, 0, fiveMinutesFromNow, isLive = true)

Then("calling isAboutToStart should return fals")
theMatch.isAboutToStart shouldBe (false)
}
}
}
Loading