safe-redirect-manager icon indicating copy to clipboard operation
safe-redirect-manager copied to clipboard

Improve check_for_possible_redirect_loops() efficiency

Open joshbetz opened this issue 10 years ago • 3 comments

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.

joshbetz avatar Apr 29 '15 17:04 joshbetz

Yup, makes sense.

tlovett1 avatar May 04 '15 01:05 tlovett1

@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

nicoladj77 avatar Nov 09 '16 21:11 nicoladj77

@jameswburke apologies for all the pings, but looks like perhaps another downstream fix that could help here?

jeffpaul avatar Jun 28 '22 20:06 jeffpaul