Skip to content

Commit 7df2296

Browse files
authored
Merge pull request #20 from DevDavido/development
Bump to v1.0.11
2 parents 082d21c + e8a65ce commit 7df2296

File tree

5 files changed

+92
-6
lines changed

5 files changed

+92
-6
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
- Added: Support for Matomo 4 🎉
44
- Updated: Bumped the minimum PHP version to 7.2.5 for this new major plugin version, just as Matomo 4 itself
55

6+
## 1.0.11
7+
- Added: Option to remove query strings from audited URLs
8+
- Improved: Small refactoring in settings
9+
610
## 1.0.10
711
- Fixed: Issue with previous release as version number was incompatible with plugin marketplace
812

MeasurableSettings.php

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ class MeasurableSettings extends BaseMeasurableSettings
2323
/** @var Setting */
2424
public $emulatedDevice;
2525

26+
/** @var Setting */
27+
public $hasUrlsWithoutQueryString;
28+
2629
/** @var Setting */
2730
public $hasExtraHttpHeader;
2831

@@ -47,6 +50,7 @@ protected function init()
4750

4851
$this->runCount = $this->makeRunCountSetting();
4952
$this->emulatedDevice = $this->makeEmulatedDeviceSetting();
53+
$this->hasUrlsWithoutQueryString = $this->makeHasUrlsWithoutQueryStringSetting();
5054
$this->hasExtraHttpHeader = $this->makeHasExtraHttpHeaderSetting();
5155
$this->extraHttpHeaderKey = $this->makeExtraHttpHeaderKeySetting();
5256
$this->extraHttpHeaderValue = $this->makeExtraHttpHeaderValueSetting();
@@ -103,6 +107,21 @@ private function makeEmulatedDeviceSetting()
103107
});
104108
}
105109

110+
/**
111+
* Create a grouped URLs setting.
112+
*
113+
* @return MeasurableSetting
114+
* @throws ValidatorException|Exception
115+
*/
116+
private function makeHasUrlsWithoutQueryStringSetting()
117+
{
118+
return $this->makeSetting('has_urls_without_query_string', false, FieldConfig::TYPE_BOOL, function (FieldConfig $field) {
119+
$field->title = Piwik::translate('PerformanceAudit_Settings_HasUrlsWithoutQueryString_Title');
120+
$field->inlineHelp = Piwik::translate('PerformanceAudit_Settings_HasUrlsWithoutQueryString_Help');
121+
$field->uiControl = FieldConfig::UI_CONTROL_CHECKBOX;
122+
});
123+
}
124+
106125
/**
107126
* Create has extra HTTP header setting.
108127
*
@@ -177,4 +196,34 @@ private function makeExtraHttpHeaderValueSetting()
177196
};
178197
});
179198
}
199+
200+
/**
201+
* Returns array of runs of site.
202+
*
203+
* @return array
204+
*/
205+
public function getRuns()
206+
{
207+
return range(1, (int) $this->getSetting('run_count')->getValue());
208+
}
209+
210+
/**
211+
* Returns list of emulated devices of site.
212+
*
213+
* @return array
214+
*/
215+
public function getEmulatedDevicesList()
216+
{
217+
return EmulatedDevice::getList($this->getSetting('emulated_device')->getValue());
218+
}
219+
220+
/**
221+
* Returns if site has URLs without query strings for site.
222+
*
223+
* @return bool
224+
*/
225+
public function hasUrlsWithoutQueryString()
226+
{
227+
return $this->getSetting('has_urls_without_query_string')->getValue();
228+
}
180229
}

Tasks.php

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,12 @@ public function auditSite(int $idSite, bool $debug = false)
109109
}
110110
$siteSettings = new MeasurableSettings($idSite);
111111

112-
$runs = range(1, (int) $siteSettings->getSetting('run_count')->getValue());
113-
$emulatedDevices = EmulatedDevice::getList($siteSettings->getSetting('emulated_device')->getValue());
112+
$runs = $siteSettings->getRuns();
113+
$emulatedDevices = $siteSettings->getEmulatedDevicesList();
114+
115+
if ($siteSettings->hasUrlsWithoutQueryString()) {
116+
$this->removeQueryStrings($urls);
117+
}
114118

115119
if ($this->isInDebugMode()) {
116120
$urls = [array_shift($urls)];
@@ -285,8 +289,35 @@ private function getPageUrls(int $idSite, string $date)
285289
}
286290
}
287291
}
292+
$this->removeUrlDuplicates($urls);
293+
294+
return $urls;
295+
}
296+
297+
/**
298+
* Remove query string from each url.
299+
*
300+
* @param array $urls
301+
* @return void
302+
*/
303+
private function removeQueryStrings(array &$urls)
304+
{
305+
foreach ($urls as $key => $url) {
306+
$urls[$key] = current(explode('?', $url, 2));
307+
}
288308

289-
return array_values(array_unique($urls, SORT_STRING));
309+
$this->removeUrlDuplicates($urls);
310+
}
311+
312+
/**
313+
* Remove url duplicates.
314+
*
315+
* @param array $urls
316+
* @return void
317+
*/
318+
private function removeUrlDuplicates(array &$urls)
319+
{
320+
$urls = array_values(array_unique($urls, SORT_STRING));
290321
}
291322

292323
/**

lang/en.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,10 @@
6767
"Settings_RunCount_Help": "Set how many times the audit should be performed on each page for stable results. Any number between 1 and 5 is possible. 5 iterations are twice as stable, but prolongs the processing time the most. Just use such high values like 5 iterations only if enough server resources are generally available. 3 iterations are usually the best balance between reproducibility and resource consumption.",
6868
"Settings_EmulatedDevice_Title": "Performance simulation environment",
6969
"Settings_EmulatedDevice_Help": "Select in what kind of environment performance audits should be executed and measured.",
70-
"Settings_HasExtraHttpHeader_Title": "Use Custom HTTP header",
71-
"Settings_HasExtraHttpHeader_Help": "If you want to add a custom HTTP header to every request, e.g. for HTTP Basic Authentication, enable this setting.",
70+
"Settings_HasUrlsWithoutQueryString_Title": "Remove query string from URLs for performance audits",
71+
"Settings_HasUrlsWithoutQueryString_Help": "If you enable this setting, URLs will get their <a href=\"https://en.wikipedia.org/wiki/Query_string\" target=\"_blank\">query string</a> removed for audits. If lots of your website requests only differ in their query string, enabling this setting can speed up the time it takes for the overall performance audit of a site. Note that only URLs with the same path but with different query strings will be removed, all other URLs are not affected by this setting.",
72+
"Settings_HasExtraHttpHeader_Title": "Use Custom HTTP header for performance audits",
73+
"Settings_HasExtraHttpHeader_Help": "If you want to add a custom HTTP header to every performance audit request, e.g. for HTTP Basic Authentication, enable this setting.",
7274
"Settings_ExtraHttpHeaderKey_Title": "Custom HTTP header key",
7375
"Settings_ExtraHttpHeaderKey_Help": "Select your custom HTTP header key.",
7476
"Settings_ExtraHttpHeaderKey_Authorization": "Authorization",

plugin.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "PerformanceAudit",
33
"description": "Daily performance audits of all your sites in Matomo.",
4-
"version": "1.0.10",
4+
"version": "1.0.11",
55
"theme": false,
66
"require": {
77
"php": ">=7.1.3",

0 commit comments

Comments
 (0)