From: octo Date: Tue, 12 Apr 2005 09:30:58 +0000 (+0000) Subject: Fixed Bignumbers Plugin X-Git-Tag: Release-0.8.0~20^2~17 X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=5c1583d69efcd6e65715721bc0013c8afe43b705;p=onis.git Fixed Bignumbers Plugin Fixed Quotes --- diff --git a/lib/Onis/Plugins/Bignumbers.pm b/lib/Onis/Plugins/Bignumbers.pm index 7e37935..46e5634 100644 --- a/lib/Onis/Plugins/Bignumbers.pm +++ b/lib/Onis/Plugins/Bignumbers.pm @@ -105,9 +105,6 @@ sub calculate $CalcData->{$main}{'uppercase'} += $uppercase; $CalcData->{$main}{'smiley_happy'} += $smiley_happy; $CalcData->{$main}{'smiley_sad'} += $smiley_sad; - - require Data::Dumper; - print STDOUT Data::Dumper->Dump ([$CalcData->{$main}], ["CalcData->{$main}"]); } } diff --git a/lib/Onis/Plugins/Core.pm b/lib/Onis/Plugins/Core.pm index fc8e3db..565b893 100644 --- a/lib/Onis/Plugins/Core.pm +++ b/lib/Onis/Plugins/Core.pm @@ -46,7 +46,9 @@ our $NickCharsCounter = Onis::Data::Persistent->new ('NickCharsCounter', 'nick', ) ); -our $QuoteCache = {}; # Saves per-nick information without any modification +our $QuoteCache = Onis::Data::Persistent->new ('QuoteCache', 'key', qw(epoch text)); +our $QuotePtr = Onis::Data::Persistent->new ('QuotePtr', 'nick', qw(pointer)); + our $QuoteData = {}; # Is generated before output. Nicks are merged according to Data::Core. our $NickData = {}; # Same as above, but for nicks rather than quotes. our $SortedNicklist = []; @@ -300,21 +302,16 @@ sub add if ((length ($text) >= $QuoteMin) and (length ($text) <= $QuoteMax)) { - if (!defined ($QuoteCache->{$nick})) - { - $QuoteCache->{$nick} = []; - } - push (@{$QuoteCache->{$nick}}, [$time, $text]); - } + my ($pointer) = $QuotePtr->get ($nick); + $pointer ||= 0; - if (defined ($QuoteCache->{$nick})) - { - while (scalar (@{$QuoteCache->{$nick}}) > $QuoteCacheSize) - { - shift (@{$QuoteCache->{$nick}}); - } - } + my $key = sprintf ("%s:%02i", $nick, $pointer); + + $QuoteCache->put ($key, $time, $text); + $pointer = ($pointer + 1) % $QuoteCacheSize; + $QuotePtr->put ($nick, $pointer); + } return (1); } @@ -378,16 +375,43 @@ sub calculate { $QuoteData->{$main} = []; } - if (defined ($QuoteCache->{$nick})) + } + + for ($QuoteCache->keys ()) + { + my $key = $_; + my ($nick, $num) = split (m/:/, $key); + my $main = get_main_nick ($nick); + + my ($epoch, $text) = $QuoteCache->get ($key); + die unless (defined ($text)); + + if (!defined ($QuoteData->{$main})) + { + die; + } + elsif (scalar (@{$QuoteData->{$main}}) < $QuoteCacheSize) + { + push (@{$QuoteData->{$main}}, [$epoch, $text]); + } + else { - my @new = (); - push (@new, @{$QuoteData->{$main}}) if (@{$QuoteData->{$main}}); - push (@new, @{$QuoteCache->{$nick}}) if (@{$QuoteCache->{$nick}}); + my $insert = -1; + my $min = $epoch; - @new = sort { $b->[0] <=> $a->[0] } (@new); - splice (@new, $QuoteCacheSize) if (scalar (@new) > $QuoteCacheSize); + for (my $i = 0; $i < $QuoteCacheSize; $i++) + { + if ($QuoteData->{$main}[$i][0] < $min) + { + $insert = $i; + $min = $QuoteData->{$main}[$i][0]; + } + } - $QuoteData->{$main} = \@new; + if ($insert != -1) + { + $QuoteData->{$main}[$insert] = [$epoch, $text]; + } } } } @@ -591,9 +615,6 @@ EOF my $num = scalar (@{$QuoteData->{$nick}}); my $rand = int (rand ($num)); - require Data::Dumper; - print STDOUT Data::Dumper->Dump ([$rand, $QuoteData->{$nick}], ['rand', "QuoteData->{$nick}"]); - $quote = html_escape ($QuoteData->{$nick}[$rand][1]); }