From: Timo Tijhof Date: Fri, 30 May 2014 05:24:27 +0000 (+0200) Subject: mediawiki.special.unwatchedPages: Use closest() instead of parents() X-Git-Tag: 1.31.0-rc.0~15535 X-Git-Url: https://git.cyclocoop.org/%28%28?a=commitdiff_plain;h=25f051d22716dff6788a7154812a7a756429dd36;p=lhc%2Fweb%2Fwiklou.git mediawiki.special.unwatchedPages: Use closest() instead of parents() Follows-up Ie32cc54abb6f. While it is unlikely that this item will ever end up being nested inside another list, it is semantically incorrect and also quite a bit slower to use parents() here. parents() collects all ancestors between this node and the document element (each and every one of the elements in between), and then, if a selector (e.g. "li") is supplied, it reduces that set to only
  • elements. This can be more than one if your list is a nested list (whether a plain sublist, or perhaps many levels apart, e.g. part of the skin layout or whatever). This one is slower (traverses all the way up) and creates two collections (all ancestors, then filtered down). closest(), as the name implies, always requires a selector and traverses only up to the first match and then returns. This one is faster (traverses only once and not all the way). A 1:1 (closest) vs. a 1:many (parents) relationship. Change-Id: I1cd9a4638285aeab4b5d538072e598601eb475b6 --- diff --git a/resources/src/mediawiki.special/mediawiki.special.unwatchedPages.js b/resources/src/mediawiki.special/mediawiki.special.unwatchedPages.js index a2c2228787..8d3e86ae5f 100644 --- a/resources/src/mediawiki.special/mediawiki.special.unwatchedPages.js +++ b/resources/src/mediawiki.special/mediawiki.special.unwatchedPages.js @@ -7,7 +7,7 @@ var promise, api = new mw.Api(), $link = $( this ), - $subjectLink = $link.parents( 'li' ).children( 'a' ).eq( 0 ), + $subjectLink = $link.closest( 'li' ).children( 'a' ).eq( 0 ), title = mw.util.getParamValue( 'title', $link.attr( 'href' ) ); // nice format title = mw.Title.newFromText( title ).toText();