[pmwiki-users] Strange issue with PageListSortCmp

Petko Yotov 5ko at 5ko.fr
Sun Sep 6 10:04:37 CDT 2015


On 2015-08-31 10:07, ABClf wrote:
> Fort the special sorting, in my config :
> 
> # sorting pages by numerical integer pagetextvar data
> function IntegerDataCompare($x, $y, $var) {
>       # get integer value of the page text variable
>       $xval = intval(PageTextVar($x, $var));
>       $yval = intval(PageTextVar($y, $var));
>       # compare integer values
>       if($xval > $yval) $c = 1;
>       elseif($xval < $yval) $c = -1;
>       else $c = 0;
>       return $c;
> }
> 
> $PageListSortCmp['registre_origine'] = 'IntegerDataCompare($x, $y,
> "registre_origine")';
> 
> My pagelist :
> 
> (:pagelist group=Bob link=Source.2048  $:registre_origine=-
> fmt=#registre order=registre_origine:)
> 
> Strangely, it's half working, half broken : data are ordered, but it
> looks like the list is splitted : I get something like this, (where x
> appears as if it were empty) : 10 10 10 9 9 8 8 7 7 6 6 5 5 4 4 3 x 10
> 10 9 9 (etc., list continues, broken several times by an empty value).

Thanks for your message and for letting me test your wiki -- it 
uncovered an issue I haven't contemplated.

This error in sorting is caused by the large number of calls to the core 
function PageTextVar(). When that happens, you quickly hit the 
$MaxPageTextVars limits which are set to prevent infinite loops like 
these:

   Var1: {$:Var2}
   Var2: {$:Var1}

Obviously, in a pagelist sorting we don't risk an infinite loop, but a 
variable of a page will be compared hundreds of times to the same 
variable on hundreds of other pages.

I have updated the custom pagelist sort functions documented in the 
Cookbook to directly use the "cached" variables instead of calling 
PageTextVar() every time:

   http://www.pmwiki.org/wiki/Cookbook/CustomPagelistSortOrderFunctions

I'll think about maybe adding a switch in the core to temporarily ignore 
$MaxPageTextVars from a custom local function. But for now use the 
helper function I wrote at the above page.

Petko

-- 
Change log     :  http://www.pmwiki.org/wiki/PmWiki/ChangeLog
Release notes  :  http://www.pmwiki.org/wiki/PmWiki/ReleaseNotes
If you upgrade :  http://www.pmwiki.org/wiki/PmWiki/Upgrades

If this message helped you and saved you time, feel free to make
a small contribution: ♥ http://5ko.fr/donate-ml (mailing list).




More information about the pmwiki-users mailing list