Permalink
Browse files

fix thundering herd of requests from MultiDrawersWidget. Bug 2756

We're avoiding creating new Cells that will fetch same bucket
details. The price is slowly leaking that cells. More correct fix will
be implemented later.

Change-Id: I11d973c41952e5ab7363cc4574d5c1d690f768de
Reviewed-on: http://review.northscale.com/3188
Tested-by: Aliaksey Kandratsenka <alkondratenko@gmail.com>
Reviewed-by: Sean Lynch <seanl@literati.org>
  • Loading branch information...
1 parent ca2e585 commit 3119b5b97755a128a4dac4a5177d7261ef7e05a0 Aliaksey Kandratsenka committed with seanlynch Oct 11, 2010
Showing with 22 additions and 12 deletions.
  1. +22 −12 deps/menelaus/priv/js/app-misc.js
@@ -347,6 +347,8 @@ var MultiDrawersWidget = mkClass({
configureActionHashParam(options.actionLink, $m(this, 'onActionLinkClick'));
}
+ this.knownKeys = {};
+
this.subscriptions = [];
this.reDrawElements = $m(this, 'reDrawElements');
this.hookRedrawToCell(this.openedNames);
@@ -374,20 +376,28 @@ var MultiDrawersWidget = mkClass({
_.each(elements, function (e) {
e[idPrefix] = _.uniqueId(idPrefix);
- var uriCell = new Cell(function (openedNames) {
- if (this.self.value || !_.include(openedNames, e[key]))
- return this.self.value;
+ var cell = self.knownKeys[e[key]];
- return self.options.uriExtractor(e);
- }, {openedNames: self.openedNames});
+ if (!cell) {
+ var uriCell = new Cell(function (openedNames) {
+ if (this.self.value || !_.include(openedNames, e[key]))
+ return this.self.value;
- var cell = e[drawerCellName] = new Cell(function (uri) {
- return future.get({url: uri}, function (childItem) {
- if (self.options.valueTransformer)
- childItem = self.options.valueTransformer(e, childItem);
- return childItem;
- });
- }, {uri: uriCell});
+ return self.options.uriExtractor(e);
+ }, {openedNames: self.openedNames});
+
+ cell = new Cell(function (uri) {
+ return future.get({url: uri}, function (childItem) {
+ if (self.options.valueTransformer)
+ childItem = self.options.valueTransformer(e, childItem);
+ return childItem;
+ });
+ }, {uri: uriCell});
+
+ self.knownKeys[e[key]] = cell;
+ }
+
+ e[drawerCellName] = cell;
var oldE = oldElementsByName[e[key]];
var oldCell = oldE && oldE[drawerCellName];

0 comments on commit 3119b5b

Please sign in to comment.