From 9b5e4571ecb35d63e687dc9942bcc95e0e125888 Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Thu, 22 Mar 2012 13:41:29 -0400 Subject: [PATCH] AutoFieldWidget single-object cache repairs Caching single objects linked off the context object was failing in most cases as it was caching under the display name instead of the true value (pkey) for the linked object. This fixes that by always caching the linked object by its true value, so that future cache lookups will be looking in the right place. Signed-off-by: Bill Erickson --- .../web/js/dojo/openils/widget/AutoFieldWidget.js | 34 ++++++++++------------ 1 file changed, 15 insertions(+), 19 deletions(-) diff --git a/Open-ILS/web/js/dojo/openils/widget/AutoFieldWidget.js b/Open-ILS/web/js/dojo/openils/widget/AutoFieldWidget.js index ad5d92b181..50d1a4f40c 100644 --- a/Open-ILS/web/js/dojo/openils/widget/AutoFieldWidget.js +++ b/Open-ILS/web/js/dojo/openils/widget/AutoFieldWidget.js @@ -389,14 +389,18 @@ if(!dojo._hasResource['openils.widget.AutoFieldWidget']) { } // then try the single object cache - if(this.cache[this.auth].single[lclass] && - this.cache[this.auth].single[lclass][this.widgetValue] && - this.cache[this.auth].single[lclass][this.widgetValue][self.labelFormat || '']) { - this.widgetValue = this.cache[this.auth].single[lclass][this.widgetValue][self.labelFormat || '']; + var item; + if(this.cache[this.auth].single[lclass] && ( + item = this.cache[this.auth].single[lclass][this.widgetValue]) ) { + + this.widgetValue = (this.labelFormat) ? + this._applyLabelFormat(item.toStoreItem(), this.labelFormat) : + item[linkInfo.vfield.selector](); + return; } - console.log("Fetching sync object " + lclass + " : " + this.widgetValue); + console.log("Fetching linked object " + lclass + " : " + this.widgetValue); // if those fail, fetch the linked object this.async = true; @@ -406,22 +410,14 @@ if(!dojo._hasResource['openils.widget.AutoFieldWidget']) { oncomplete : function(r) { var item = openils.Util.readResponse(r); - var newvalue = item[linkInfo.vfield.selector](); - - var labelCacheKey = ''; - - if(self.labelFormat) { - labelCacheKey = self.labelFormat; - self.widgetValue = self._applyLabelFormat(item.toStoreItem(), self.labelFormat); - } else { - self.widgetValue = newvalue; - } - + // cache the true object under its real value if(!self.cache[self.auth].single[lclass]) self.cache[self.auth].single[lclass] = {}; - if(!self.cache[self.auth].single[lclass][self.widgetValue]) - self.cache[self.auth].single[lclass][self.widgetValue] = {}; - self.cache[self.auth].single[lclass][self.widgetValue][labelCacheKey] = newvalue; + self.cache[self.auth].single[lclass][self.widgetValue] = item; + + self.widgetValue = (self.labelFormat) ? + self._applyLabelFormat(item.toStoreItem(), self.labelFormat) : + item[linkInfo.vfield.selector](); self.widget.startup(); self._widgetLoaded(); -- 2.11.0