I was able to replicate the problem after applying the proposed patch...
I created a large number of tags for a few articles (~90) and then deleting a bunch of them (and their respective relations to articles) from the faqtags table on the back end. This is similar to the process I used to clear out faqdata_tags in my other post (
viewtopic.php?f=3&t=9787) . Clearing unused tags from the faqtags table appears to cause the problem. So ... one *shouldn't* see this problem unless they are doing some house-cleaning directly on the database as the current version doesn't delete unused tags from the faqtags table.
The reason it gets stuck in a loop is that it exhausts the possible number of matches whose index is less than the number of tags. When a large number of tags are deleted, the maximum index is much larger than the number of tags. The while loop finds all of the tags whose index is less than or equal to the number of tags. When all of those tags are found, the while loop gets stuck.
Using a modified version of Cory's original proposed patch:
add a function outside the class:
Code: Select all
function scmp($a, $b){
return rand(-1,1);
}
Then replace
Code: Select all
for ($n = 0; $n < $numberOfItems; $n++) {
$valid = false;
while (!$valid) {
$rand = rand(1, count($allTags) + 1);
if (!isset($soFar[$rand])) {
if (isset($allTags[$rand])) {
$valid = true;
$soFar[$rand] = '';
$tags[$rand] = $allTags[$rand];
}
}
with
Code: Select all
$tags=$allTags;
uasort($tags, 'scmp');
$tags=array_slice(0, $numberOfItems);
I haven't fully tested this on a densely populated DB... Can you review this and confirm it is sufficient and compatible with other functions?
Cheers,
Eric