Skip to content

Commit

Permalink
Do not lookup pressed fronts in S3 if front does not exist
Browse files Browse the repository at this point in the history
Co-authored-by: Jamie B <[email protected]>
  • Loading branch information
georgeblahblah and JamieB-gu committed May 15, 2024
1 parent c917e22 commit 691a020
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
3 changes: 3 additions & 0 deletions common/app/services/ConfigAgentTrait.scala
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,9 @@ object ConfigAgent extends GuLogging {
def shouldServeFront(id: String)(implicit context: ApplicationContext): Boolean =
getPathIds.contains(id) && (context.isPreview || !isFrontHidden(id))

def frontExistsInConfig(id: String)(implicit context: ApplicationContext): Boolean =
getPathIds.contains(id)

def shouldServeEditionalisedFront(edition: Edition, id: String)(implicit context: ApplicationContext): Boolean = {
shouldServeFront(s"${edition.id.toLowerCase}/$id")
}
Expand Down
29 changes: 20 additions & 9 deletions facia/app/controllers/FaciaController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,15 @@ trait FaciaController
FrontHeadline.headlineNotFound
}

frontJsonFapi
.get(path, liteRequestType)
.map(_.fold[CacheableResult](notFound())(FrontHeadline.renderEmailHeadline))
.map(Cached(CacheTime.Facia))
if (!ConfigAgent.frontExistsInConfig(path)) {
successful(Cached(CacheTime.Facia)(notFound()))
} else {
frontJsonFapi
.get(path, liteRequestType)
.map(_.fold[CacheableResult](notFound())(FrontHeadline.renderEmailHeadline))
.map(Cached(CacheTime.Facia))
}

}

def renderFront(path: String): Action[AnyContent] =
Expand Down Expand Up @@ -170,11 +175,17 @@ trait FaciaController
// see https://github.com/guardian/pressreader
def renderFrontJsonMinimal(path: String): Action[AnyContent] =
Action.async { implicit request =>
frontJsonFapi.get(path, liteRequestType).map { resp =>
Cached(CacheTime.Facia)(JsonComponent.fromWritable(resp match {
case Some(pressedPage) => FapiFrontJsonMinimal.get(pressedPage)
case None => JsObject(Nil)
}))
if (!ConfigAgent.frontExistsInConfig(path)) {
successful(
Cached(CacheTime.Facia)(JsonComponent.fromWritable(JsObject(Nil))),
)
} else {
frontJsonFapi.get(path, liteRequestType).map { resp =>
Cached(CacheTime.Facia)(JsonComponent.fromWritable(resp match {
case Some(pressedPage) => FapiFrontJsonMinimal.get(pressedPage)
case None => JsObject(Nil)
}))
}
}
}

Expand Down

0 comments on commit 691a020

Please sign in to comment.