--- Save.pm.save1 2006-02-07 07:08:45.000000000 -0800 +++ Save.pm 2006-04-12 17:53:48.000000000 -0700 @@ -283,6 +283,37 @@ $session->{topicName} = $topic; } + # Allow for more flexible topic creation with sortable names and + # better performance. See Codev.AutoIncTopicNameOnSave + if( $topic =~ /AUTOINC([0-9]+)/ ) { + my $start = $1; + my $baseTopic = $topic; + $store->clearLease( $web, $baseTopic ); + my $nameFilter = $topic; + $nameFilter =~ s/AUTOINC([0-9]+)/([0-9]+)/; + my @list = + sort{ $a <=> $b } + map{ s/^$nameFilter$/$1/; s/^0*([0-9])/$1/; $_ } + grep{ /^$nameFilter$/ } + $store->getTopicNames( $web ); + if( scalar @list ) { + # find last one, and increment by one + my $next = $list[$#list] + 1; + my $len = length( $start ); + $start =~ s/^0*([0-9])/$1/; # cut leading zeros + $next = $start if( $start > $next ); + my $pad = $len - length($next); + if( $pad > 0 ) { + $next = '0' x $pad . $next; # zero-pad + } + $topic =~ s/AUTOINC[0-9]+/$next/; + } else { + # first auto-inc topic + $topic =~ s/AUTOINC[0-9]+/$start/; + } + $session->{topicName} = $topic; + } + my $redirecturl = $session->getScriptUrl( 1, 'view', $web, $topic ); my $saveaction = '';