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
Fixed issue #19555: afterFindSurvey gets triggered excessively #3840
base: master
Are you sure you want to change the base?
Fixed issue #19555: afterFindSurvey gets triggered excessively #3840
Conversation
The function afterSurveyFind do some other things For example LimeSurvey/application/models/Survey.php Line 588 in c2b4fd9
I think it's better too to have it only one time but
Need some unit test too to check if
|
The afterFind LS plugin event is tightly related to the onAfterFind Yii event. What is being suggested here looks more to me like:
I would just:
Also, of course, clarify the situation with the documentation. |
#3816 (comment) It seems to me the issue should be solved starting from the stated purpose of the event. Why this event exists, what is the purpose of the event? The description of the event in the documentation could be old version/date-wise but there might not have anything significant changed code-wise for that specific event after documenting it. I'm not sure which way is better to go, it depends on how LS states the purpose of the event. Currently I see the fact is that the stated purpose and actual behavior do not match. People using the event for the stated functionality end up calling the event excessively possibly without realizing it (I know I was). 'afterInit' - you mean afterInit Survey model? This seems very similar to the current afterFindSurvey essentially. I personally do not see use for that and have no comment on possible afterInitSurvey. |
Agree. So I would create a new event so people can start moving to use that event that better fits their situation.
Similar, but would only be triggered once. |
The issue is this one : With 3.X and before : LimeSurvey don't use $question->survey (and no pjax/ajax call (not a lot)) Then when using survey->findByPk : we call it one time when we work on a survey. Seems the new versions : 5 and master have
My opinion :
Maybe we need to update the way Yii return $question->survey ? If we have a $question->getSurvey : it happen when we use $question->survey ? There the ajax call : multiple call for one HTML page, but i think we really reduce here. |
I mean the new event should be triggered much less than the current afterFind. Expectedly, once.
I if ti shall be used for survey taking process, we could name it beforeSurveyLoadSurvey |
I think that's already done.
I wouldn't update how this works. I would create a new event for it. |
It work like that when it was created and updated : you have to reset the static variable in beforeSureyPage to allow update (i have a plugin with this). The 5.X system work not like 3.X system then. |
There is some additional discussion regarding this fix in #3816
The afterFindSurvey event gets triggered each time survey is found found via
Survey::findByPk()
, but as well always when survey is found via relations eg$question->survey
.With a survey page of multiple questions and even sub-questions the event
afterFindSurvey
might get triggered tens of times on one survey page load.There is a discussion whether this is a bug or a feature.
It's a feature view
afterFindSurvey
event is tightly related to instantianting any survey object, also meaning it must be triggered after initializing a survey via relations or any time a survey object is populated. In this case it is not a bug and we should not fix it, this PR should be closed.It's a bug view
The event manual states that the event is for:
This means the whole display session (survey page) - meaning it does not need to be triggered tens of times during a a page load.
It is not related to initializing any Survey object it is meant specifically to trigger after
Survey::findByPk()
. In this case It's a bug and this PR will move the triggering essentially from populating any survey record to specifically only ifSurvey::findByPk()
returns a new object (not stored also viaSurvey::$findByPkCache
)