Skip Navigation

[Resolved] I will have quite a few of these statements on the page with up to 3 variables in each statement

This thread is resolved. Here is a description of the problem and solution.

Problem:
The user is using several combinations of conditions on custom fields, and wonders if there is any performance impact between nesting or combining conditions.

Solution:
You can nest the conditions to avoid long statements and to have much readable code. But from a performance perspective, I don't think there will be an impact between combining or nesting the conditions. Primarily, because the values will be cached in memory after they are first pulled from the database. And they won't be pulled again.

Nesting the conditions may gain a couple of instructions executions, but I don't think it will be considerable.

This support ticket is created 4 years, 6 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 - - 9:00 – 13:00
14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 - - 14:00 – 18:00

Supporter timezone: Africa/Casablanca (GMT+01:00)

This topic contains 6 replies, has 2 voices.

Last updated by GamX 4 years, 6 months ago.

Assisted by: Jamal.

Author
Posts
#1754195

Follow up question... I will have quite a few of these statements on the page with up to 3 variables in each statement. Would it be better to nest them, or to have a bunch of individual statements like the one above (which may include 3 variables) with different combinations of values? I want to make each page load as quickly as possible.

#1756267

Hello and thank you for contacting the Toolset support.

I would say that both ways(combine or nest) are similar, but this, actually, depends on the type of variable that you are using. Can you provide more details on what conditions and variables you will use?

#1757015

Sure. For context, this is an online course where the user responds to Toolset Custom User Fields throughout, then these values are either displayed back to the user so it feels more personalized, or they are used to create conditional views so the user sees different things depending on what they've chosen in the past.

Below is an example post. All forms are User Forms, and all fields are User fields attached to the Current User. Fork field options are Left (1), Right (2), Straight (3). Fork Solution options are Solution 1, Solution 2, Solution 3.

As you can see, I have a lot of different combinations of field values in the statements below with some redundancy… wondering if it is better to nest them inside common conditions instead?

<!-- ***FIRST TIME VISIT TO PAGE, OR REFRESH FROM DIFFERENT PAGE*** —>
<!-- ***LEFT FORK*** -->
[wpv-conditional if="('[wpv-search-term param="_success"]' EQ '') AND ('[types usermeta='fork' output='raw' current_user='true'][/types]' EQ '1')"]
You have taken the left fork, and you have not yet responded to the Fork Solution Form.
[cred_user_form form='fork-solution-form']
[/wpv-conditional]

<!-- ***RIGHT FORK*** -->
[wpv-conditional if="('[wpv-search-term param="_success"]' EQ '') AND ('[types usermeta='fork' output='raw' current_user='true'][/types]' EQ '2')"]
You have taken the right fork, and you have not yet responded to the Fork Solution Form.
[cred_user_form form='fork-solution-form']
[/wpv-conditional]

<!-- ***STRAIGHT*** -->
[wpv-conditional if="('[wpv-search-term param="_success"]' EQ '') AND ('[types usermeta='fork' output='raw' current_user='true'][/types]' EQ '3')"]
You have gone straight at the fork, and you have not yet responded to the Fork Solution Form.
[cred_user_form form='fork-solution-form']
[/wpv-conditional]

<!-- ***AFTER RESPONSE TO FORK-SOLUTION-FORM*** -->
<!-- ***LEFT FORK – SOLUTION 1*** -->
[wpv-conditional if="('[wpv-search-term param="_success"]' NE '') AND ('[types usermeta='fork' output='raw' current_user='true'][/types]' EQ '1') AND ('[types usermeta='fork-solution' output='raw' current_user='true'][/types]' EQ '1')"]
You met an obstacle on the Left path and chose Solution 1. But this solution won’t work. You must make another choice.
[cred_user_form form='fork-solution-form']
[/wpv-conditional]

<!-- ***LEFT FORK – SOLUTION 2*** -->
[wpv-conditional if="('[wpv-search-term param="_success"]' NE '') AND ('[types usermeta='fork' output='raw' current_user='true'][/types]' EQ '1') AND ('[types usermeta='fork-solution' output='raw' current_user='true'][/types]' EQ '2')"]
You met an obstacle on the Left path and chose Solution 2. This was the best solution.
[/wpv-conditional]

<!-- ***LEFT FORK – SOLUTION 3*** -->
[wpv-conditional if="('[wpv-search-term param="_success"]' NE '') AND ('[types usermeta='fork' output='raw' current_user='true'][/types]' EQ '1') AND ('[types usermeta='fork-solution' output='raw' current_user='true'][/types]' EQ '3')"]
You met an obstacle on the Left path and chose Solution 3. This was not the best solution but will work with extra effort.
[/wpv-conditional]

<!-- ***RIGHT FORK – SOLUTION 1*** -->
[wpv-conditional if="('[wpv-search-term param="_success"]' NE '') AND ('[types usermeta='fork' output='raw' current_user='true'][/types]' EQ '2') AND ('[types usermeta='fork-solution' output='raw' current_user='true'][/types]' EQ '1')"]
You met an obstacle on the Right path and chose Solution 1. This was not the best solution but will work with extra effort.
[/wpv-conditional]

<!-- ***RIGHT FORK – SOLUTION 2*** -->
[wpv-conditional if="('[wpv-search-term param="_success"]' NE '') AND ('[types usermeta='fork' output='raw' current_user='true'][/types]' EQ '2') AND ('[types usermeta='fork-solution' output='raw' current_user='true'][/types]' EQ '2')"]
You met an obstacle on the Right path and chose Solution 2. But this solution won’t work. You must make another choice.
[cred_user_form form='fork-solution-form']
[/wpv-conditional]

<!-- ***RIGHT FORK – SOLUTION 3*** -->
[wpv-conditional if="('[wpv-search-term param="_success"]' NE '') AND ('[types usermeta='fork' output='raw' current_user='true'][/types]' EQ '2') AND ('[types usermeta='fork-solution' output='raw' current_user='true'][/types]' EQ '3')"]
You met an obstacle on the Right path and chose Solution 3. This was the best solution.
[/wpv-conditional]

<!-- ***STRAIGHT – SOLUTION 1*** -->
[wpv-conditional if="('[wpv-search-term param="_success"]' NE '') AND ('[types usermeta='fork' output='raw' current_user='true'][/types]' EQ '3') AND ('[types usermeta='fork-solution' output='raw' current_user='true'][/types]' EQ '1')"]
You met an obstacle on the Straight path and chose Solution 1. This was the best solution.
[/wpv-conditional]

<!-- ***STRAIGHT – SOLUTION 2*** -->
[wpv-conditional if="('[wpv-search-term param="_success"]' NE '') AND ('[types usermeta='fork' output='raw' current_user='true'][/types]' EQ '3') AND ('[types usermeta='fork-solution' output='raw' current_user='true'][/types]' EQ '2')"]
You met an obstacle on the Straight path and chose Solution 2. This was not the best solution but will work with extra effort.
[/wpv-conditional]

<!-- ***STRAIGHT – SOLUTION 3*** -->
[wpv-conditional if="('[wpv-search-term param="_success"]' NE '') AND ('[types usermeta='fork' output='raw' current_user='true'][/types]' EQ '3') AND ('[types usermeta='fork-solution' output='raw' current_user='true'][/types]' EQ '3')"]
You met an obstacle on the Straight path and chose Solution 3. But this solution won’t work. You must make another choice.
[cred_user_form form='fork-solution-form']
[/wpv-conditional]

<!-- ***COMMON – if not left-solution1, right-solution2, or straight-solution3*** -->
[wpv-conditional if="('[wpv-search-term param="_success"]' NE '') AND ('[types usermeta='fork' output='raw' current_user='true'][/types]' NE '[types usermeta='fork-solution' output='raw' current_user='true'][/types]')"]
This is what you see if you have already responded to the Fork Solution Form, and if the combination of your Fork choice (made in the previous post) and your Fork Solution choice (made in this post) do NOT meet any of the following criteria:
- You turned left at the fork and chose solution #1
- You turned right at the fork and chose solution #2
- You went straight at the fork and chose solution #3
[/wpv-conditional]

#1757577

From what I see so far the conditions are matched against:
- The search param "_success".
- The custom field "fork".
- The custom field "fork-solution".

You can nest the conditions to avoid long statements and to have much readable code. But from a performance perspective, I don't think there will be an impact between combining or nesting the conditions. Primarily, because the values will be cached in memory after they are first pulled from the database. And they won't be pulled again.

Nesting the conditions may gain a couple of instructions executions, but I don't think it will be considerable.

I hope this answers your question, let me know if you have any doubts or others questions.

#1758189

Thanks Jamal, that's extremely helpful. I forgot to mention - I recently activated Gutenberg and it converted my Toolset pages into Classic Blocks with html like I shared above. Do you think it's better to leave them in that form, or would it be okay to convert them to the Toolset conditional blocks, text and fields box, etc.? I am concerned about performance...

#1758229

I would recommend converting the whole page to blocks and using conditional blocks instead of one or multiple classic blocks.

From a performance perspective, either way, won't have a significant difference. You can build a new page and test both cases from a performance/speed perspective.

To gain performance, I would suggest implementing a caching system, using a caching plugin such as:
1. WP Rocket
2. W3 Total Cache
3. WP Super Cache

Please note, that "WP Rocket" is a premium plugin. The 2nd and 3rd are free.

#1758269

Thanks for such clear and practical advice, Jamal!