Skip to content

Commit

Permalink
use regex instead of string comparison and reorder ignored user agents
Browse files Browse the repository at this point in the history
  • Loading branch information
empiricompany committed May 13, 2023
1 parent b3c9dab commit 46803c1
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 14 deletions.
12 changes: 9 additions & 3 deletions app/code/core/Mage/Log/Model/Visitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,17 @@ protected function _construct()
if ($ignoreAgents) {
$ignoreAgents = $ignoreAgents->asArray();
$userAgent = $this->_httpHelper->getHttpUserAgent();
foreach ($ignoreAgents as $ignoreAgent) {
if (stripos($userAgent, $ignoreAgent) !== false) {
try {
$ignoreAgents = array_map(function ($userAgent) {
return preg_quote($userAgent, '/');
}, $ignoreAgents);
$ignoreAgentRegex = implode('|', $ignoreAgents);

if (preg_match("/{$ignoreAgentRegex}/i", $userAgent)) {
$this->_skipRequestLogging = true;
break;
}
} catch (Exception $e) {
Mage::logException($e);
}
}
}
Expand Down
26 changes: 15 additions & 11 deletions app/code/core/Mage/Log/etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,24 +29,28 @@
</entities>
</ignoredModules>
<ignore_user_agents>
<google>Googlebot</google>
<mauibot>MauiBot</mauibot>
<blexbot>BLEXBot</blexbot>
<hrefsbot>AhrefsBot</hrefsbot>
<adsbot>AdsBot</adsbot>
<alphabot>AlphaBot</alphabot>
<amazonbot>Amazonbot</amazonbot>
<bingbot>bingbot</bingbot>
<blexbot>BLEXBot</blexbot>
<dotbot>DotBot</dotbot>
<facebookexternalhit>facebookexternalhit</facebookexternalhit>
<google>Googlebot</google>
<google-site-verification>Google-Site-Verification</google-site-verification>
<hrefsbot>AhrefsBot</hrefsbot>
<istellabot>istellabot</istellabot>
<mod_pagespeed>mod_pagespeed</mod_pagespeed>
<mauibot>MauiBot</mauibot>
<mj12bot>MJ12bot</mj12bot>
<yandexbot>YandexMobileBot</yandexbot>
<yandeximage>YandexImages</yandeximage>
<mod_pagespeed>mod_pagespeed</mod_pagespeed>
<opensiteexplorer>spbot</opensiteexplorer>
<pinterestbot>Pinterestbot</pinterestbot>
<semrushbot>SemrushBot</semrushbot>
<alphabot>AlphaBot</alphabot>
<facebookexternalhit>facebookexternalhit</facebookexternalhit>
<seotester>SEOTesterBot</seotester>
<ZoominfoBot>ZoominfoBot</ZoominfoBot>
<amazonbot>Amazonbot</amazonbot>
<yandexbot>YandexBot</yandexbot>
<yandeximage>YandexImages</yandeximage>
<yandexmobilebot>YandexMobileBot</yandexmobilebot>
<zoominfobot>ZoominfoBot</zoominfobot>
</ignore_user_agents>
<helpers>
<log>
Expand Down

0 comments on commit 46803c1

Please sign in to comment.