r88115 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r88114‎ | r88115 | r88116 >
Date:17:56, 14 May 2011
Author:catrope
Status:resolved
Tags:
Comment:
(bug 28978) jquery.autoEllipsis cache doesn't take position into account, leads to cache pollution
Modified paths:
  • /trunk/phase3/resources/jquery/jquery.autoEllipsis.js (modified) (history)

Diff [purge]

Index: trunk/phase3/resources/jquery/jquery.autoEllipsis.js
@@ -3,7 +3,7 @@
44 */
55 ( function( $ ) {
66
7 -// Cache ellipsed substrings for every string-width combination
 7+// Cache ellipsed substrings for every string-width-position combination
88 var cache = { };
99 // Use a seperate cache when match highlighting is enabled
1010 var matchTextCache = { };
@@ -49,29 +49,40 @@
5050 var w = $container.width();
5151 var pw = $protectedText ? $protectedText.width() : 0;
5252 // Try cache
53 - if ( !( text in cache ) ) {
54 - cache[text] = {};
55 - }
56 - if ( options.matchText && !( text in matchTextCache ) ) {
57 - matchTextCache[text] = {};
58 - }
59 - if ( options.matchText && !( options.matchText in matchTextCache[text] ) ) {
60 - matchTextCache[text][options.matchText] = {};
61 - }
62 - if ( !options.matchText && w in cache[text] ) {
63 - $container.html( cache[text][w] );
64 - if ( options.tooltip ) {
65 - $container.attr( 'title', text );
 53+ if ( options.matchText ) {
 54+ if ( !( text in matchTextCache ) ) {
 55+ matchTextCache[text] = {};
6656 }
67 - return;
68 - }
69 - if( options.matchText && options.matchText in matchTextCache[text] && w in matchTextCache[text][options.matchText] ) {
70 - $container.html( matchTextCache[text][options.matchText][w] );
71 - if ( options.tooltip ) {
72 - $container.attr( 'title', text );
 57+ if ( !( options.matchText in matchTextCache[text] ) ) {
 58+ matchTextCache[text][options.matchText] = {};
7359 }
74 - return;
 60+ if ( !( w in matchTextCache[text][options.matchText] ) ) {
 61+ matchTextCache[text][options.matchText][w] = {};
 62+ }
 63+ if ( options.position in matchTextCache[text][options.matchText][w] ) {
 64+ $container.html( matchTextCache[text][options.matchText][w][options.position] );
 65+ if ( options.tooltip ) {
 66+ $container.attr( 'title', text );
 67+ }
 68+ return;
 69+ }
 70+ } else {
 71+ if ( !( text in cache ) ) {
 72+ cache[text] = {};
 73+ }
 74+ if ( !( w in cache[text] ) ) {
 75+ cache[text][w] = {};
 76+ }
 77+ if ( options.position in cache[text][w] ) {
 78+ $container.html( cache[text][w][options.position] );
 79+ if ( options.tooltip ) {
 80+ $container.attr( 'title', text );
 81+ }
 82+ console.log("YAY CACHE HIT");
 83+ return;
 84+ }
7585 }
 86+
7687 if ( $trimmableText.width() + pw > w ) {
7788 switch ( options.position ) {
7889 case 'right':
@@ -122,9 +133,9 @@
123134 }
124135 if ( options.matchText ) {
125136 $container.highlightText( options.matchText );
126 - matchTextCache[text][options.matchText][w] = $container.html();
 137+ matchTextCache[text][options.matchText][w][options.position] = $container.html();
127138 } else {
128 - cache[text][w] = $container.html();
 139+ cache[text][w][options.position] = $container.html();
129140 }
130141
131142 } );

Follow-up revisions

RevisionCommit summaryAuthorDate
r88150Remove debugging code introduced in r88115catrope10:57, 15 May 2011

Status & tagging log