@@ -27,18 +27,33 @@ class PrerenderClient implements PrerenderClientInterface
27
27
/** @var LoggerInterface */
28
28
private LoggerInterface $ logger ;
29
29
30
+ /**
31
+ *
32
+ * @param Config $prerenderConfigHelper
33
+ * @param ClientInterface $client
34
+ * @param SerializerInterface $jsonSerializer
35
+ * @param LoggerInterface $logger
36
+ */
30
37
public function __construct (
31
38
Config $ prerenderConfigHelper ,
32
39
ClientInterface $ client ,
33
40
SerializerInterface $ jsonSerializer ,
34
41
LoggerInterface $ logger
35
42
) {
36
43
$ this ->prerenderConfigHelper = $ prerenderConfigHelper ;
37
- $ this ->client = $ client ;
38
44
$ this ->jsonSerializer = $ jsonSerializer ;
39
45
$ this ->logger = $ logger ;
46
+ $ this ->client = $ client ;
47
+ $ this ->client ->addHeader ('content-type ' , 'application/json ' );
40
48
}
41
49
50
+ /**
51
+ * Call Prerender.io API to recache list of URLs
52
+ *
53
+ * @param array $urls
54
+ * @param int $storeId
55
+ * @return void
56
+ */
42
57
public function recacheUrls (array $ urls , int $ storeId ): void
43
58
{
44
59
if (!$ this ->prerenderConfigHelper ->isRecacheEnabled ($ storeId )) {
@@ -50,16 +65,19 @@ public function recacheUrls(array $urls, int $storeId): void
50
65
return ;
51
66
}
52
67
53
- if (count ($ urls ) > self ::MAX_URLS ) {
54
- $ batches = array_chunk ($ urls , self ::MAX_URLS );
55
- foreach ($ batches as $ batch ) {
56
- $ this ->sendRequest ($ batch , $ token );
57
- }
58
- } else {
59
- $ this ->sendRequest ($ urls , $ token );
68
+ $ batches = array_chunk ($ urls , self ::MAX_URLS );
69
+ foreach ($ batches as $ batch ) {
70
+ $ this ->sendRequest ($ batch , $ token );
60
71
}
61
72
}
62
73
74
+ /**
75
+ * Sends a JSON POST request to Prerender.io
76
+ *
77
+ * @param array $urls
78
+ * @param string $token
79
+ * @return void
80
+ */
63
81
private function sendRequest (array $ urls , string $ token ): void
64
82
{
65
83
$ payload = $ this ->jsonSerializer ->serialize (
@@ -68,7 +86,6 @@ private function sendRequest(array $urls, string $token): void
68
86
'urls ' => $ urls
69
87
]
70
88
);
71
- $ this ->client ->addHeader ('content-type ' , 'application/json ' );
72
89
try {
73
90
$ this ->client ->post (self ::PRERENDER_RECACHE_URL , $ payload );
74
91
} catch (\Exception $ e ) {
0 commit comments