Permalink
Browse files

D2 update: add "retrieve by date" functionality, improve efficiency, …

…fix bugs
  • Loading branch information...
1 parent 7c5fba0 commit 4ea441b7d0e2af02fd591a72e0f30d44c01ecec2 @pudge pudge committed Aug 23, 2007
Showing with 81 additions and 53 deletions.
  1. +57 −42 Slash/Slash.pm
  2. +18 −10 plugins/Ajax/htdocs/ajax.pl
  3. +1 −0 themes/slashcode/htdocs/users.pl
  4. +5 −1 themes/slashcode/templates/editComm;users;default
View
@@ -47,7 +47,7 @@ $VERSION = '2.005000'; # v2.5.0
dispComment displayStory displayRelatedStories displayThread dispStory
getOlderStories getOlderDays getOlderDaysFromDay printComments
- jsSelectComments commentCountThreshold
+ jsSelectComments commentCountThreshold commentThresholds
tempUofmLinkGenerate tempUofmCipherObj
);
@@ -151,21 +151,26 @@ sub selectComments {
$options->{existing} ||= {};
@$thisComment = sort { $a->{cid} <=> $b->{cid} } @$thisComment;
- if (1) { # XXXd2 by score
- for my $C (sort { $b->{points} <=> $a->{points} || $a->{cid} <=> $b->{cid} } @$thisComment) {
- next if $options->{existing}{$C->{cid}};
+ my $sort_comments;
+ if (!$user->{d2_comment_order}) { # score
+ $sort_comments = [ sort {
+ $b->{points} <=> $a->{points}
+ ||
+ $a->{cid} <=> $b->{cid}
+ } @$thisComment ];
+ } else { # date / cid
+ $sort_comments = $thisComment;
+ }
- if ($cid) {
- if (@new_comments >= $max) {
- push @new_comments, $C if $cid == $C->{cid};
- } else {
- push @new_comments, $C;
- }
- } else {
- push @new_comments, $C;
- last if @new_comments >= $max;
- }
+ for my $C (@$sort_comments) {
+ next if $options->{existing}{$C->{cid}};
+
+ if ($cid && @new_comments >= $max) {
+ push @new_comments, $C if $cid == $C->{cid};
+ } else {
+ push @new_comments, $C;
}
+ last if !$cid && @new_comments >= $max;
}
my @seen;
@@ -311,9 +316,9 @@ sub jsSelectComments {
$user ||= getCurrentUser();
$form ||= getCurrentForm();
- $user->{mode} = 'thread';
- $user->{reparent} = 0;
- $user->{state}{max_depth} = $constants->{max_depth} + 3;
+ my $id = $form->{sid};
+ my $pid = $form->{cid} || 0;
+ return unless $id;
my $threshold = defined $user->{d2_threshold} ? $user->{d2_threshold} : $user->{threshold};
my $highlightthresh = defined $user->{d2_highlightthresh} ? $user->{d2_highlightthresh} : $user->{highlightthresh};
@@ -323,33 +328,23 @@ sub jsSelectComments {
}
$highlightthresh = $threshold if $highlightthresh < $threshold;
- my $id = $form->{sid};
- return unless $id;
-
- my $pid = $form->{cid} || 0;
-
- my($comments) = selectComments(
- $slashdb->getDiscussion($id),
- $pid,
- {
- commentsort => 0,
- threshold => -1
- }
- );
+ # only differences:
+ # sco: force_read, one_cid_only, threshold (was -1 here, matters?)
+ my($comments) = $user->{state}{selectComments}{comments};
my $d2_seen_0 = $comments->{0}{d2_seen} || '';
- delete $comments->{0}; # non-comment data
+ #delete $comments->{0}; # non-comment data
if ($pid && exists $comments->{$pid}) {
$comments = _get_thread($comments, $pid);
}
- my @roots = $pid ? $pid : grep { !$comments->{$_}{pid} } keys %$comments;
+ my @roots = $pid ? $pid : grep { $_ && !$comments->{$_}{pid} } keys %$comments;
my %roots_hash = ( map { $_ => 1 } @roots );
my $thresh_totals;
if ($form->{full}) {
my $comment_text = $slashdb->getCommentTextCached(
- $comments, [ keys %$comments ],
+ $comments, [ grep $_, keys %$comments ],
);
for my $cid (keys %$comment_text) {
@@ -358,7 +353,7 @@ sub jsSelectComments {
} else {
my $comments_new;
my @keys = qw(pid kids points uid);
- for my $cid (keys %$comments) {
+ for my $cid (grep $_, keys %$comments) {
@{$comments_new->{$cid}}{@keys} = @{$comments->{$cid}}{@keys};
# we only care about it if it is not original ... we could
@@ -434,17 +429,12 @@ sub commentCountThreshold {
}
}
- for my $cid (keys %$comments) {
+ for my $cid (grep $_, keys %$comments) {
next if $comments->{$cid}{dummy};
- my $T = $comments->{$cid}{points};
- my $HT = $T;
- if (!$user->{is_anon} && $user->{uid} == $comments->{$cid}{uid}) {
- $T = 5;
- }
+
+ my($T, $HT) = commentThresholds($comments->{$cid}, $roots_hash->{$cid}, $user);
if ($cid == $pid) {
$HT += 7; # THE root comment is always full
- } elsif ($roots_hash->{$cid}) {
- $HT++;
}
for my $i (-1..$T) {
@@ -466,6 +456,25 @@ sub commentCountThreshold {
return \%thresh_totals;
}
+sub commentThresholds {
+ my($comment, $root, $user) = @_;
+ $user ||= getCurrentUser();
+
+ my $T = $comment->{points};
+ my $HT = $T;
+
+ if (!$user->{is_anon} && $user->{uid} == $comment->{uid}) {
+ $T = 5;
+ }
+
+ if ($root) {
+ $HT++;
+ }
+
+ return($T, $HT);
+}
+
+
sub _get_thread {
my($comments, $pid, $newcomments) = @_;
$newcomments ||= {};
@@ -892,6 +901,12 @@ sub printComments {
$sco->{one_cid_only} = 0;
my($comments, $count) = selectComments($discussion, $cidorpid, $sco);
+ if ($discussion2) {
+ $user->{state}{selectComments} = {
+ comments => $comments,
+ count => $count
+ };
+ }
if ($cidorpid && !exists($comments->{$cidorpid})) {
# No such comment in this discussion.
@@ -88,6 +88,8 @@ sub main {
$slashdb, $constants, $user, $form, $options
);
+# print STDERR "AJAX7 $$: $user->{uid}, $op ($retval)\n";
+
if ($retval) {
header_ajax($options);
print $retval;
@@ -294,7 +296,7 @@ sub fetchComments {
my @placeholders;
$user->{state}{ajax_accesslog_op} = "ajax_comments_fetch";
-#use Data::Dumper; print STDERR Dumper [ $cids, $id, $cid, $max_cid ];
+#use Data::Dumper; print STDERR Dumper [ $cids, $id, $cid, $max_cid, $d2_seen ];
# XXX error?
return unless $id && ($max_cid || @$cids || $d2_seen);
@@ -336,7 +338,7 @@ sub fetchComments {
return unless $comments && keys %$comments;
my $d2_seen_0 = $comments->{0}{d2_seen} || '';
- delete $comments->{0}; # non-comment data
+ #delete $comments->{0}; # non-comment data
my %data;
if ($max_cid || $d2_seen || $placeholders) {
@@ -351,7 +353,7 @@ sub fetchComments {
)}
];
} elsif ($d2_seen) {
- $special_cids = $cids = [ sort { $a <=> $b } grep { !$seen{$_} } keys %$comments ];
+ $special_cids = $cids = [ sort { $a <=> $b } grep { $_ && !$seen{$_} } keys %$comments ];
} elsif ($placeholders) {
@placeholders = split /[,;]/, $placeholders;
$special_cids = [ sort { $a <=> $b } @placeholders ];
@@ -380,7 +382,7 @@ sub fetchComments {
my %cid_map = map { ($_ => 1) } @$special_cids;
$data{new_thresh_totals} = commentCountThreshold(
- { map { ($_ => $comments->{$_}) } grep { $cid_map{$_} } keys %$comments },
+ { map { ($_ => $comments->{$_}) } grep { $_ && $cid_map{$_} } keys %$comments },
0,
{ map { ($_ => 1) } grep { !$comments->{$_}{pid} } @$special_cids }
);
@@ -408,14 +410,20 @@ sub fetchComments {
if ($comment->{dummy}) {
$class = 'hidden';
$keep_hidden{$cid} = 1;
- } elsif ($comment->{points} < $form->{threshold}) {
- if ($user->{is_anon} || ($user->{uid} != $comment->{uid})) {
- $class = 'hidden';
- $keep_hidden{$cid} = 1;
+ } else {
+ # for now we only readjust for children of ROOT (pid==0);
+ # if we make this work for threads, we will need to know
+ # the pid of the page, and adjust this accordingly
+ my($T, $HT) = commentThresholds($comment, !$comment->{pid}, $user);
+ if ($T < $form->{threshold}) {
+ if ($user->{is_anon} || ($user->{uid} != $comment->{uid})) {
+ $class = 'hidden';
+ $keep_hidden{$cid} = 1;
+ }
}
+ $class = 'full' if $HT >= $form->{highlightthresh}
+ && $class ne 'hidden';
}
- $class = 'full' if $comment->{points} >= $form->{highlightthresh}
- && $class ne 'hidden';
$comment->{class} = $class;
if ($class eq 'oneline') {
@@ -2746,6 +2746,7 @@ sub saveComm {
my $user_edits_table = {
discussion2 => $form->{discussion2} || undef,
d2_comment_q => $form->{d2_comment_q} || undef,
+ d2_comment_order => $form->{d2_comment_order} || undef,
clsmall => $form->{clsmall},
clsmall_bonus => ($clsmall_bonus || undef),
clbig => $form->{clbig},
@@ -66,7 +66,11 @@ __template__
How Many Comments
[% comment_q = Slash.db.getDescriptions('d2_comment_q');
comment_q_def = user_edit.d2_comment_q || 0;
- Slash.createSelect('d2_comment_q', comment_q, comment_q_def, 1) %]
+ Slash.createSelect('d2_comment_q', comment_q, comment_q_def, 1) %]<br>
+ Comment Retrieval Order
+ [% comment_order = Slash.db.getDescriptions('d2_comment_order');
+ comment_order_def = user_edit.d2_comment_order || 0;
+ Slash.createSelect('d2_comment_order', comment_order, comment_order_def, 1) %]
</div></blockquote>
[% END %]

0 comments on commit 4ea441b

Please sign in to comment.