Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update visit only when needed #15869

Merged
merged 3 commits into from Apr 28, 2020
Merged

Update visit only when needed #15869

merged 3 commits into from Apr 28, 2020

Conversation

tsteur
Copy link
Member

@tsteur tsteur commented Apr 27, 2020

On every log_visit update it will try to update the idvisitor with the same value. In theory even if there was no other value to update then it will do updateVisit($idVisit, array('idvisitor' => '...')) which be unneeded. As the value in most queries won't change this PR likely doesn't have an impact but be still good to have as it would avoid the need for checking that field on every log_visit update and if no other log_visit field is needed to be updated, then it avoids the query altogether.

@tsteur tsteur added this to the 3.13.6 milestone Apr 27, 2020
@tsteur tsteur added c: Performance For when we could improve the performance / speed of Matomo. Needs Review PRs that need a code review labels Apr 27, 2020
@tsteur tsteur changed the title Update idvisitor only when needed Update visit only when needed Apr 28, 2020
@@ -877,10 +877,22 @@ private function triggerHookOnDimensions(Request $request, $dimensions, $hook, $

private function getGoalFromVisitor(VisitProperties $visitProperties, Request $request, $action)
{
$lastVisitTime = $visitProperties->getProperty('visit_last_action_time');
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this part is not 100% related to this PR. It refs matomo-org/matomo-for-wordpress#215 (comment) figured since it is related to visit last action time etc might fix that as well.

@diosmosis
Copy link
Member

Code looks good, some system tests are failing though.

@tsteur
Copy link
Member Author

tsteur commented Apr 28, 2020

@diosmosis just fixed the tests. They should pass now. I looked into it and the changed values are expected as it fixes an issue where eg when

  • track pageview with request time 2020-05-05 05:05:05
  • track pageview with request time 2020-05-05 05:06:05
  • track pageview with request time 2020-05-05 05:04:05

And then it would falsely overwrite the last_visit_action_time 2020-05-05 05:06:05 with the value 2020-05-05 05:04:05. Causing eg the session to expire earlier (hence it has now one less visit in some reports because it could link a request to an existing visit) and also the visit time decreases as it more correctly calculates it.

Eg it first tracks an event where it adds 5 minutes: https://github.com/matomo-org/matomo/blob/3.13.5/tests/PHPUnit/Fixtures/ThreeVisitsWithCustomEvents.php#L134-L137

Then it tracks events where it adds only one minute or two minutes: https://github.com/matomo-org/matomo/blob/3.13.5/tests/PHPUnit/Fixtures/ThreeVisitsWithCustomEvents.php#L96-L106

And therefore it sets a lower visit_last_action_time and therefore before it was calculating wrong time on site in that case

@tsteur
Copy link
Member Author

tsteur commented Apr 28, 2020

@diosmosis fyi tests pass now

@diosmosis diosmosis merged commit 2466e9f into 3.x-dev Apr 28, 2020
@diosmosis diosmosis deleted the updateidvisitor branch April 28, 2020 22:54
jonasgrilleres pushed a commit to 1024pix/pix-analytics that referenced this pull request Sep 22, 2020
* update idvisitor only when needed

* better implementation

* fix tests
jbuget pushed a commit to 1024pix/pix-analytics that referenced this pull request Sep 26, 2020
* update idvisitor only when needed

* better implementation

* fix tests
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c: Performance For when we could improve the performance / speed of Matomo. Needs Review PRs that need a code review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants