File tree Expand file tree Collapse file tree 1 file changed +16
-6
lines changed Expand file tree Collapse file tree 1 file changed +16
-6
lines changed Original file line number Diff line number Diff line change @@ -9,16 +9,26 @@ import play.api.cache.Cached
9
9
import play .api .libs .json .Json ._
10
10
import play .api .mvc ._
11
11
12
+ import scala .Function .unlift
12
13
import scala .concurrent .ExecutionContext .Implicits .global
13
- import scala .concurrent .Future
14
+ import scala .concurrent .duration ._
15
+ import scala .language .postfixOps
14
16
15
17
class Api @ Inject () (cached : Cached ) extends Controller {
16
18
17
- def messageLookup (repoId : RepoId , query : String ) = cached(s " $repoId $query" ) {
18
- Action .async {
19
- for {
20
- messagesOpt <- Project .byRepoId(repoId).mailingList.lookupMessage(query)
21
- } yield Ok (toJson(messagesOpt : Seq [MessageSummary ]))
19
+ val MessageFoundHeader = " X-submitGit-MessageFound"
20
+
21
+ val CacheForLongerIfMessageFound = unlift[ResponseHeader , Duration ](_.headers.get(MessageFoundHeader ).map(_ => 100 days))
22
+
23
+ def messageLookup (repoId : RepoId , query : String ) = {
24
+ cached.apply((_ => s " $repoId $query" ): (RequestHeader => String ), CacheForLongerIfMessageFound ).default(3 seconds) {
25
+ Action .async {
26
+ for {
27
+ messagesOpt <- Project .byRepoId(repoId).mailingList.lookupMessage(query)
28
+ } yield {
29
+ Ok (toJson(messagesOpt : Seq [MessageSummary ])).withHeaders(messagesOpt.map(_ => MessageFoundHeader -> " true" ) : _* )
30
+ }
31
+ }
22
32
}
23
33
}
24
34
You can’t perform that action at this time.
0 commit comments