wp-rocket
wp-rocket copied to clipboard
Guard against unnecessary request when RUCSS and Preload are used together
Before submitting an issue please check that you’ve completed the following steps:
- Made sure you’re on the latest version
- Used the search feature to ensure that the bug hasn’t been reported before
Describe the bug When RUCSS and Preload are used together it's possible that we'll do one additional, unnecessary request to the URL.
To Reproduce Steps to reproduce the behavior:
- Enable Preload and RUCSS, make sure that the Cache and Used CSS are not present yet
- Preload will start triggering Used CSS requests to SaaS
- Click on the
Clear and Preload
the Cache - Pages that are waiting for the Used CSS will be preloaded
- When we receive the Used CSS, they'll be cleared and preloaded once again to inject the Used CSS
Expected behavior Pages that are waiting for the Used CSS should not be preloaded.
Additional context That's not very likely scenario to happen but it's good to save as many resources as possible.
Backlog Grooming (for WP Media dev team use only)
- [ ] Reproduce the problem
- [ ] Identify the root cause
- [ ] Scope a solution
- [ ] Estimate the effort
Scope a solution
We could create add a filter in the loop changing rows to in-progress that returns true
by default so it will guard from passing that row in-progress
.
(We could also make a request to modify that row even we don't pass it in-progress
so it will go at the end from the preload queue and thus will not block the preload on the next batch)
Then we could register that same filter on the RUCSS part and make a query to the database to check if this URL is pending in the RUCSS table and return false if it is the case.
What do you think @engahmeds3ed ?
Estimate effort
Effort S
Scope a solution
To prevent unnecessary requests we can create a lock system on the preload that would prevent locked rows from being loaded.
For that we will need:
- To add a new column
is_locked
on the table cache with aboolean
. - To create an action
rocket_preload_lock_url
and anotherrocket_preload_unlock_url
that will lock or unlock a URL passed in parameter. - On RUCSS we will add two calls to each actions in each scenario possible:
- One at this line where we will call the action
rocket_preload_lock_url
with the current url. - One inside this condition where we will call the action
rocket_preload_unlock_url
with the row details.
- One at this line where we will call the action
- One at this line where we will call the action
rocket_preload_unlock_url
with the row details.
Estimate effort
Effort S