)
);
-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 = [];
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);
}
$NickData->{$main}{'words_total'} = $sum;
}
- @counter = $NickWordsCounter->get ($nick);
+ @counter = $NickCharsCounter->get ($nick);
if (@counter)
{
my $sum = 0;
for (my $i = 0; $i < 24; $i++)
{
- $NickData->{$main}{'words'}[$i] += $counter[$i];
+ $NickData->{$main}{'chars'}[$i] += $counter[$i];
$sum += $counter[$i];
}
$NickData->{$main}{'chars_total'} = $sum;
{
$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 = sort (sub { $b->[0] <=> $a->[0] }, @{$QuoteCache->{$nick}}, @{$QuoteData->{$main}});
- splice (@new, $QuoteCacheSize) if (scalar (@new) > $QuoteCacheSize);
- $QuoteData->{$main} = \@new;
+ my $insert = -1;
+ my $min = $epoch;
+
+ for (my $i = 0; $i < $QuoteCacheSize; $i++)
+ {
+ if ($QuoteData->{$main}[$i][0] < $min)
+ {
+ $insert = $i;
+ $min = $QuoteData->{$main}[$i][0];
+ }
+ }
+
+ if ($insert != -1)
+ {
+ $QuoteData->{$main}[$insert] = [$epoch, $text];
+ }
}
}
}
my $nick = $_;
my $ident = nick_to_ident ($nick);
my $name = ident_to_name ($ident);
+ my $print = $name || $nick;
$linescount++;
{
my $quote = translate ('-- no quote available --');
- if (defined ($QuoteData->{$nick}))
+ if (@{$QuoteData->{$nick}})
{
my $num = scalar (@{$QuoteData->{$nick}});
my $rand = int (rand ($num));
- $quote = html_escape ($QuoteData->{$nick}[$rand]);
+
+ $quote = html_escape ($QuoteData->{$nick}[$rand][1]);
}
my $link = '';
if ($link)
{
- print $fh qq#<a href="$link">$name</a></td>\n#
+ print $fh qq#<a href="$link">$print</a></td>\n#
}
else
{
- print $fh qq#$name</td>\n#;
+ print $fh qq#$print</td>\n#;
}
if ($DISPLAY_LINES ne 'NONE')
qq# <tr>\n#;
}
- print $fh qq# <td title="$title">$name ($total)</td>\n#;
+ print $fh qq# <td title="$title">$print ($total)</td>\n#;
if ($row_in_this_table == $ShortLines and $col_in_this_table == 5)
{