In #2616330: statistics.php can exit early and prevent output errors we added some test to call statistics.php.
@dawehner pointed out that we could simplify the guzzle declaration.
Specifically
- $this->client = \Drupal::service('http_client_factory')
- ->fromOptions(['config/curl' => [CURLOPT_TIMEOUT => 10]]);
+ $this->client = new Client(['timeout' => 10]);
And add a use statement for the guzzle client. use GuzzleHttp\Client;
More specifically the 'old' declaration way is used in
- core/modules/statistics/src/Tests/StatisticsAdminTest.php
- core/modules/statistics/src/Tests/StatisticsLoggingTest.php
- core/modules/statistics/src/Tests/StatisticsReportsTest.php
- core/modules/statistics/src/Tests/StatisticsTokenReplaceTest.php
| Comment | File | Size | Author |
|---|---|---|---|
| #29 | interdiff-2785997-28-29.txt | 723 bytes | faline |
| #29 | cleanup_guzzle-2785997-29.patch | 3.87 KB | faline |
| #28 | interdiff-2785997-22-28.txt | 0 bytes | faline |
| #28 | cleanup_guzzle-2785997-28.patch | 3.03 KB | faline |
| #22 | interdiff-2785997-18-22.txt | 851 bytes | faline |
Comments
Comment #2
dawehnerAs asked on the other issue: Why do we actually have a custom timeout in the first place? Maybe some git blame will give us some idea about it.
Comment #3
chanderbhushan commentedHi,
I have updated listed files:-
core/modules/statistics/src/Tests/StatisticsAdminTest.php
core/modules/statistics/src/Tests/StatisticsLoggingTest.php
Not find these line in two rest files.
Comment #4
chanderbhushan commentedComment #5
chanderbhushan commentedComment #7
chanderbhushan commentedadding new patch
Comment #8
chanderbhushan commentedComment #9
chanderbhushan commentedComment #10
mallezieThanks here.
However after some testing in #2616330: statistics.php can exit early and prevent output errors
We discovered the declaration directly to guzzle is not gonna work, we need the 'Drupal' guzzle clietn.
So the declaration of the client would need to be.
$this->client = \Drupal::httpClient();
Your patch also contains some unrelated changes.
Comment #12
chanderbhushan commentedadded new patch
Comment #13
chanderbhushan commentedComment #14
mallezieThanks! I think this one should pass.
But the patch still contains unrelated changes from files changed in views.
Actually only the first two hunks of the patch should be here.
Comment #15
chanderbhushan commentedHI,
@mallezie removed unrelated changes from files. Added new patch
thanks
Comment #16
chanderbhushan commentedComment #17
mallezieLooks great, only one minor point.
There was suggested to remove the timeout. The default setup gives a timeout of 30, there is no reason to set a specific one here.
So we could simply replace
$this->client = \Drupal::httpClient(['timeout' => 10]);
with
$this->client = \Drupal::httpClient();
Comment #18
chanderbhushan commentedthanks! @mallezie removed and added new patch.
Comment #19
chanderbhushan commentedComment #20
mallezieI'm sorry, but i missed that since the approach changed during this issue.
Actually the use Guzzle statements are not needed anymore, they actually should be removed. (just saw it need to do the same in #2616330: statistics.php can exit early and prevent output errors).
Comment #21
mr.baileysAgreed on the removal of the timeout value. It was added in #1209532-109: Count node views via AJAX in the statistics module, but that issue did not contain any reasoning why that value was chosen, so falling back to the default timeout value seems fine.
So the only change left is to remove the Guzzle-use-statements. Tagging as novice.
Comment #22
faline commentedRemoving use Guzzle statements from patch #18
Comment #23
dawehnerSo wait, why are we not fixing all 4 instances which exists according to the issue summary, but rather just 2 of them?
Comment #24
faline commented@dawehner I think is because comment #3
Comment #25
dawehner@faline
Well I checked earlier and they seemed to be there. Do you mind checking again?
Comment #26
faline commented@dawehner Sure! I take a look and you are right
in both there are this code (probably this occurs because they are looking for $this->client and in these files there is only $client).
I will update the patch with this two files.
Comment #27
faline commented@dawehner I founded one more in /core/modules/statistics/src/Tests/Views/IntegrationTest.php.
Should I change that too?
Comment #28
faline commentedThis patch fixing all 4 instances according to the issue summary
Comment #29
faline commentedIn addition to the 4 mentioned, this patch also correcting the file /core/modules/statistics/src/Tests/Views/IntegrationTest.php.
Comment #30
mallezie@faline. Thanks for bringing this home. This looks great! And nice find on the 5th one.
Comment #31
dawehnerThank you @faciline
Great findings!
Comment #32
cilefen commentedComment #33
xjmUpdating the scope based on the inclusion of the Views test. Nice work finding the additional usage!
Comment #36
xjmReally great work on this issue, everyone. It's definitely helpful to see that we checked why this was introduced in the first place and also looked for other similar issues in core. Those are two of the things I check almost every time I review an RTBC patch!
I agree with removing the unneeded overrride for the timeout and letting it fall back to the default; 10 vs. 30 is not worth hardcoding a magic number.
There are two other places in core that the
http_client_factoryservice is used. One is inlocale.batch.inc:And then in Aggregator, the service is actually injected in
core/modules/aggregator/src/Plugin/aggregator/fetcher/DefaultFetcher.php:Those are not the same usecase, so I agree that the scope for this issue makes sense as is.
Committed and pushed to both 8.3.x and 8.2.x. (Since it is only changing tests and there is no disruption, this makes sense to backport to keep the branches more in sync). Thanks!