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
Fix behavior keepalive - Revert #7363
Conversation
$refresh_time = ($life_time <= 60000) ? 45000 : $life_time - 60000; | ||
|
||
// The longest refresh period is one hour to prevent integer overflow. | ||
if ($refresh_time > 3600000 || $refresh_time <= 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can the refresh time ever be less than 0 now we have the check on the life time being less than 60000 above?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It could be 0 but not less in the current constellation (if you set the value to 0 in the configuration, then the session time is set to 15 min internally). I just took this check from code that we had before I've merged the PR. So, this should be fine.
then what about that issue #6730 ?
but this means that session will be refreshed only for the Site, and not for the Administrator if I login to Administrator, or I wrong? |
@Fedik Valid point, you are right. The request has to be executed to the backend to refresh the correct session. To avoid the 500 Internal Error we could just call the index.php instead of the Ajax component. What do you think? |
hm, idea was to reduce the load ... upd: |
If the session time is set to something large (e.g. 1 hour) and it's now every 45 seconds you haven't really reduced load :P |
why not? when you do request to Ajax component, then Joomla render nothing, and do not do request to DB for load "Latest Article", "Popular Article" and so on |
but about that #6730 issue, |
So, we need 2 changes:
|
Yup |
yes, from my point of view 😉 about error |
@Fedik The "problem" is caused in administrator/includes/helper.php - function findOption. If the user is not logged in, we set the option variable to com_login which leads to this error. We could add an exception for the Ajax component but we would have to examine whether such a change would not produce side-effects. |
then maybe in this case more simple and safe is to do workaround for keepalive, than change administrator/includes/helper.php behavior if($app->isAdmin() && !JFactory::getUser()->get('id'))
{
$url = JUri::base(true) . '/index.php';
}
else
{
$url = JUri::base(true) . '/index.php?option=com_ajax&format=json';
} or something like that... |
Okay, I think we can live with the request to the index.php in the backend for now and later optimize it further. I will update the PR soon! |
I think that I've found the perfect solution! :-) If the handler is not "Database", then the refresh time is set to 5 minutes. Usually the PHP session timeout is set to 24 minutes, so 5 minutes should be safe enough. For the database handler we have the normal behavior depending on the session lifetime. We also always use the Ajax component to reduce the load except on the login page of the backend. Only on this login page we call the index.php to avoid the 500 Error. |
This diff will fix the test failure: diff --git a/tests/unit/suites/libraries/cms/html/JHtmlBehaviorTest.php b/tests/unit/suites/libraries/cms/html/JHtmlBehaviorTest.php
index 987b926..31e2342 100644
--- a/tests/unit/suites/libraries/cms/html/JHtmlBehaviorTest.php
+++ b/tests/unit/suites/libraries/cms/html/JHtmlBehaviorTest.php
@@ -630,17 +630,10 @@ class JHtmlBehaviorTest extends TestCase
// We generate a random template name so that we don't collide or hit anything//
$template = 'mytemplate' . rand(1, 10000);
- // We create a stub (not a mock because we don't enforce whether it is called or not)
- // to return a value from getTemplate
- $mock = $this->getMock('myMockObject', array('getTemplate'));
- $mock->expects($this->any())
+ // We create a stub (not a mock because we don't enforce whether it is called or not) to return a value from getTemplate
+ JFactory::$application->expects($this->any())
->method('getTemplate')
- ->will($this->returnValue($template));
-
- // @todo We need to mock this.
- $mock->input = new JInput;
-
- JFactory::$application = $mock;
+ ->willReturn($template);
JHtmlBehaviorInspector::keepalive();
$this->assertEquals( |
@mbabker Thank you, Michael. I will update the test method. |
@Kubik-Rubik thanks! works good here |
PR works great. tested with all handlers. This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/7363. |
RTC 😄 This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/7363. |
Fix behavior keepalive - Revert
This is an improvement (some kind of revert) of the PR that I've merged yesterday. After a discussion with @wilsonge and @mbabker we decided to restore some parts of the code. There is no need to refresh the session independent of the set session time. In the previous PR the refresh period was set to a fixed value (45 seconds), so if the session time was set ,for example, to 30 minutes there would be a lot of unnecessary requests.
Now the refresh time is always one minute less than the session time except if the session time is set to one minute, then the fresh time is 45 seconds.
Another important change is to use root instead of base for the request URL because the request created a 500 Internal Error on the login page of the administrator area. I've just found this bug while testing my own PR...
How to test
Since we restore the functionality to the default behavior, you won't see a "before / after" change. But you can test the keepalive behavior in general (here backend, also applies to the frontend):
@wilsonge or @mbabker Please check and commit the PR. Thanks!