safe-redirect-manager
safe-redirect-manager copied to clipboard
Improve check_for_possible_redirect_loops() efficiency
Currently, check_for_possible_redirect_loops() compares each redirect to every other redirect twice.
We should be able to do something like this to improve efficiency.
for ( $i = 0; $i < count( $redirects ); $i++ ) {
for ( $j = $i + 1; $j < count( $redirects ); $j++ ) {
// compare $redirects[$i] to $redirects[$j]
}
}
If we're checking each redirect against itself when it is originally created, the inner loop can be $j = $i + 1, otherwise it needs to be $j = $i.
Yup, makes sense.
@tlovett1 wouldn't it make for sense to check for duplicates when creating a redirect? I don't think that there is a reason to redirect onto the same page.
check_for_possible_redirect_loops might make more sense if triggered by a get parameter like srpcheck=1 so that even if the filter is active, the check is not performed on every request but only when, for instance, you press a button in the admin page. This would allow you to check for legacy broken redirects
@jameswburke apologies for all the pings, but looks like perhaps another downstream fix that could help here?