@@ -158,6 +158,10 @@ public function initByRequest($observer)
158
158
159
159
$ this ->setLastVisitAt ((new \DateTime ())->format (\Magento \Framework \Stdlib \DateTime::DATETIME_PHP_FORMAT ));
160
160
161
+ // prevent saving Visitor for safe methods, e.g. GET request
162
+ if ($ this ->getRequest ()->isSafeMethod ()) {
163
+ return $ this ;
164
+ }
161
165
if (!$ this ->getId ()) {
162
166
$ this ->setSessionId ($ this ->session ->getSessionId ());
163
167
$ this ->save ();
@@ -177,7 +181,8 @@ public function initByRequest($observer)
177
181
*/
178
182
public function saveByRequest ($ observer )
179
183
{
180
- if ($ this ->skipRequestLogging || $ this ->isModuleIgnored ($ observer )) {
184
+ // prevent saving Visitor for safe methods, e.g. GET request
185
+ if ($ this ->skipRequestLogging || $ this ->getRequest ()->isSafeMethod () || $ this ->isModuleIgnored ($ observer )) {
181
186
return $ this ;
182
187
}
183
188
@@ -321,15 +326,15 @@ public function getOnlineInterval()
321
326
* If the request wasn't injected because of the backward compatible optional constructor dependency,
322
327
* create a new request instance.
323
328
*
324
- * @return \Magento\Framework\App\RequestInterface |\Magento\Framework\App\Request\Http
329
+ * @return \Magento\Framework\App\RequestSafetyInterface |\Magento\Framework\App\Request\Http
325
330
*/
326
331
private function getRequest ()
327
332
{
328
- if (null === $ this ->request ) {
329
- $ this ->request = \Magento \Framework \App \ObjectManager::getInstance ()->create (
333
+ if (null === $ this ->requestSafety ) {
334
+ $ this ->requestSafety = \Magento \Framework \App \ObjectManager::getInstance ()->create (
330
335
\Magento \Framework \App \RequestInterface::class
331
336
);
332
337
}
333
- return $ this ->request ;
338
+ return $ this ->requestSafety ;
334
339
}
335
340
}
0 commit comments