MW-1026: Avoiding session reset upon database preview #3745
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is a performance patch, a direct follow-up of my chat with @Shnoulle about session reset in
setVariableAndTokenMappingsForExpressionManager
being executed too often, slowing down the entire system. According to my tests, there are cases when we set the preview mode to 'database' and therefore we reset for each group because of the criteria atLimeSurvey/application/helpers/expressions/em_manager_helper.php
Line 3279 in ad0a1d6
We can see that if the preview is not equivalent to false, then we end up doing the entirety of the reset for each and every call, so when we loop the groups at
LimeSurvey/application/models/services/Proxy/ProxyExpressionManager.php
Line 63 in ad0a1d6
LimeSurvey/application/helpers/expressions/em_manager_helper.php
Line 4539 in ad0a1d6
LimeSurvey/application/models/services/Proxy/ProxyExpressionManager.php
Line 49 in ad0a1d6
so we do a reset for each and every group and that eats up all our memory and time resources, creating spikes.
We will need to check other use-cases of this feature as well whether we have similar preview mode sets that slow down the entire system.
Measurements:
Survey1 Text Element Save 1 15.49s - 3.25
Survey1 Reload: 1.85 - 0.34s
Survey1 Start: 2.62s - 1.94s
Survey2 Reload: 11.56s -> 0.81s
Survey2 Text Element Save 4.3 minutes - 40.68s
Survey2 Start: 21.6s - 20 s