[dw-free] (jquery beta) thread expander slow; leads to unresponsive script errors
[commit: http://hg.dwscoalition.org/dw-free/rev/fd0aa994cac9]
http://bugs.dwscoalition.org/show_bug.cgi?id=4387
Detect expandable comments quickly using the dwexpandcomment class, instead
of testing each and every div for an id == faster. Layouts which don't have
any "dwexpcomment" class in them will still have expansion work, but will be
slower.
Patch by
allen.
Files modified:
http://bugs.dwscoalition.org/show_bug.cgi?id=4387
Detect expandable comments quickly using the dwexpandcomment class, instead
of testing each and every div for an id == faster. Layouts which don't have
any "dwexpcomment" class in them will still have expansion work, but will be
slower.
Patch by
![[personal profile]](https://www.dreamwidth.org/img/silk/identity/user.png)
Files modified:
- bin/upgrading/s2layers/core2.s2
- bin/upgrading/s2layers/zesty/layout.s2
- htdocs/js/jquery.threadexpander.js
- htdocs/talkread.bml
-------------------------------------------------------------------------------- diff -r 8ce0cb7c58a2 -r fd0aa994cac9 bin/upgrading/s2layers/core2.s2 --- a/bin/upgrading/s2layers/core2.s2 Fri Mar 30 21:23:45 2012 +0800 +++ b/bin/upgrading/s2layers/core2.s2 Fri Mar 30 23:15:08 2012 +0800 @@ -5824,7 +5824,7 @@ var string parity = $c.depth % 2 ? "odd" : "even"; var int indent = ($c.depth - 1) * 25; "<div class='comment-thread comment-depth-$parity comment-depth-$c.depth'>\n"; - "<div id='$c.dom_id' style='margin-left: ${indent}px; margin-top: 5px;"; + "<div id='$c.dom_id' class='dwexpcomment' style='margin-left: ${indent}px; margin-top: 5px;"; if ($c.hidden_child) { " display: none;"; } diff -r 8ce0cb7c58a2 -r fd0aa994cac9 bin/upgrading/s2layers/zesty/layout.s2 --- a/bin/upgrading/s2layers/zesty/layout.s2 Fri Mar 30 21:23:45 2012 +0800 +++ b/bin/upgrading/s2layers/zesty/layout.s2 Fri Mar 30 23:15:08 2012 +0800 @@ -2234,7 +2234,7 @@ function EntryPage::print_comment(Comment c) : void { - var string class = "comment " + alternate("odd", "even"); + var string class = "comment dwexpcomment " + alternate("odd", "even"); var string subject = ($c.subject == "") ? $*text_nosubject : $c.subject; var string state = "state"; diff -r 8ce0cb7c58a2 -r fd0aa994cac9 htdocs/js/jquery.threadexpander.js --- a/htdocs/js/jquery.threadexpander.js Fri Mar 30 21:23:45 2012 +0800 +++ b/htdocs/js/jquery.threadexpander.js Fri Mar 30 23:15:08 2012 +0800 @@ -112,6 +112,14 @@ } if (replies.length > 0) { + // get all comments and map them by id. this seems to be more efficient + // in jquery (at least for the results of an ajax request). + var newComments = $(".dwexpcomment", data); + var newCommentMap = {}; + newComments.each(function() { + newCommentMap[$(this).attr("id")] = $(this); + }); + for (var cmtIdCnt = 0; cmtIdCnt < replies.length; cmtIdCnt++) { var cmtId = replies[cmtIdCnt]; // if we're a valid comment, and either the comment is not expanded @@ -119,7 +127,11 @@ if (/^\d*$/.test(cmtId) && (talkid == cmtId || (! LJ[cmtId].full))) { var cmtElement = $('#cmt' + cmtId); if (cmtElement.length > 0) { - var newComment = $("#cmt" + cmtId, data); + var newComment = newCommentMap["cmt" + cmtId]; + // if there's no match, check the (slower) way. + if (! newComment) { + newComment = $("#cmt" + cmtId, data); + } if (newComment) { if (isS1) { var oldWidth = getS1SpacerObject(cmtElement).width(); diff -r 8ce0cb7c58a2 -r fd0aa994cac9 htdocs/talkread.bml --- a/htdocs/talkread.bml Fri Mar 30 21:23:45 2012 +0800 +++ b/htdocs/talkread.bml Fri Mar 30 23:15:08 2012 +0800 @@ -431,7 +431,7 @@ my $hidestyle = $post->{'hidden_child'} ? " style=\"display: none;\"" : ""; if ($post->{'state'} eq "D") { - $ret .= "<div class='comment' id='$htmlid'><p><a name='$htmlid'></a><table summary='' class='delcomment'$hidestyle><tr>"; + $ret .= "<div class='comment dwexpcomment' id='$htmlid'><p><a name='$htmlid'></a><table summary='' class='delcomment'$hidestyle><tr>"; $ret .= "<td class='spacer'><img src='$LJ::IMGPREFIX/dot.gif' alt='' height='1' width='" . ($opts->{'depth'} * 25) . "'></td>"; $ret .= "<td>$ML{'.deletedpost'}</td>"; if ($post->{'hide_children'} && $post->{'children'} && @{$post->{'children'}}) { @@ -515,7 +515,7 @@ $editreason = "($editreason)" if $editreason; } - $ret .= "<div class='comment' id='$htmlid'><table summary='' width='100%' class='talk-comment'><tbody><tr>"; + $ret .= "<div class='comment dwexpcomment' id='$htmlid'><table summary='' width='100%' class='talk-comment'><tbody><tr>"; $ret .= "<td rowspan='2' class='spacer'><img src='$LJ::IMGPREFIX/dot.gif' alt='' height='1' width='" . ($opts->{'depth'} * 25) . "'></td>"; $ret .= "<td id='cmtbar$dtid' class='cmtbar $level $additional_classes' width='100%'>"; @@ -706,7 +706,7 @@ # link to message my $url = LJ::Talk::talkargs( $talkurl, "thread=$dtid", $style_args ) . LJ::Talk::comment_anchor( $dtid ); - $ret .= "<div class='comment' id='$htmlid'$hidestyle><table summary=''><tbody><tr>"; + $ret .= "<div class='comment dwexpcomment' id='$htmlid'$hidestyle><table summary=''><tbody><tr>"; $ret .= "<td class='spacer'><img src='$LJ::IMGPREFIX/dot.gif' alt='' height='1' width='" . ($opts->{'depth'} * 25) . "'></td>"; $ret .= "<td class='cmtpartial'>"; if ($post->{'state'} eq 'F') { --------------------------------------------------------------------------------