Wp-rocket: Database Optimization: "Optimize" button doesn't perform optimization on previously selected option

Created on 10 Apr 2018  路  8Comments  路  Source: wp-media/wp-rocket

Several customers have reported that their previously selected option doesn't successfully complete the optimization when they click "Optimize". They have to deselect the option and click "Optimize," and then reselect the option and click "Optimize" again for it to work. An example ticket:
https://secure.helpscout.net/conversation/557363449/64780/?folderId=1724284

Per a slack convo with @Tabrisrp, it looks to be related to how the button functions. Our previous separation with two buttons for "Save and Optimize" and "Optimize," allowed for newly selected options to be optimized with the first button (Save and Optimize) and previously selected items to be optimized with the second option (Optimize). The current 3.0 behavior is like the first button.

Not sure if we could restore this separation or come to another solution?

bug

All 8 comments

The behavior expected with the "Optimize" button in the 3.0 was to be the same than "Save & Optimize" in 2.11.

Geoffrey wanted to reduce the number of actions here and having a single button to make both "Save & Optimize".

Regarding your explanation, of the 2.11 behavior, we also had some issues nope?

For example, If I do these steps:

  • set the database option for the first time with: Revisions & Spam comments
  • I click on "Save & Optimize", it will delete the Revisions & Spam comments
  • Few days later, I decide to also turn on Auto Drafts & Trashed posts
  • I click again on "Save & Optimize"

What will happen?

If I understand well, it means that only Auto Drafts & Trashed posts will be empty. But what about my new Revisions & Spam comments, I have to click on "Optimize"?

@GeekPress thanks for the explanation. I am wondering if there is a way to avoid having the customer to reset options to get new items optimized? @Tabrisrp would need to confirm, but could the 3.0 "Optimize" perform both actions that 2.11 offered "Save and Optimize" and "Optimize"?

Behaviour in 2.11:

  • Save & Optimize optimized the database only if a setting was changed
  • Optimize optimized the database, but didn't save the options

Behaviour in 3.0:

  • Optimize = Save & Optimize from 2.11

It's not possible to have this button perform both. It's hooked on the update_option action, which is only triggered if there was a change in the settings.

Currently the label of the button is misleading.

We could have another button to optimize in our quick actions section on the dashboard for example.

We could have another button to optimize in our quick actions section on the dashboard for example.

I feel incredibly strongly that the button to optimize needs to be on the database tab, not only somewhere else. (It could be elsewhere in addition, but must be on the db tab)

We cannot have a button labelled "Optimize" and not have it ..... Optimize.

Easiest solution is just to go back to how it was before.

To still have only one button which does both all the time "Save & Optimize", we can try:

  • add a new hidden option with a unique id
  • thanks to this random value, when we click on "Optimize", update_option hook will be triggered
  • to optimize the database only when we click on "Optimize", we can check the submit button value wp_rocket_settings[submit_optimize]

It should do the trick

This feels like a code hack to fix a design issue to me. It's the kind of magic trick are "quick & easy fix" but can introduce edge cases, makes the code more complex and less maintanable on the long run.

Having one button isn't a design fix, it's a UX improvement.

Even for us it wasn't very clear how it really works with 2 buttons before your explanation.

If you can find a solution to be able to have only "Optimize" button, it will be great for our customers and avoiding confusions.

After discussing with Greg on this topic yesterday, we determined the best course of action would be to use the pre_update_option_{$option} filter, and update part of the Database Optimization class to create a proxy method to handle both cases with one button.

Was this page helpful?
0 / 5 - 0 ratings