www

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | Submodules | README | LICENSE

commit 5a045f5b50fe2fc77963019c33a585c399794beb
parent b1389bfc61bfd5dfec584aeb0be199d62f2e6811
Author: Dan Stillman <dstillman@zotero.org>
Date:   Mon, 12 Jun 2006 12:59:25 +0000

Cache item type names to prevent repeated DB lookups in ItemTypes.getTypeName()


Diffstat:
Mchrome/chromeFiles/content/scholar/xpcom/data_access.js | 25+++++++++++++++++++++++--
1 file changed, 23 insertions(+), 2 deletions(-)

diff --git a/chrome/chromeFiles/content/scholar/xpcom/data_access.js b/chrome/chromeFiles/content/scholar/xpcom/data_access.js @@ -1624,6 +1624,10 @@ Scholar.Creators = new function(){ Scholar.ItemTypes = new function(){ + var _itemTypes = new Array(); + var _itemTypesLoaded; + var self = this; + this.getTypes = getTypes; this.getTypeName = getTypeName; @@ -1633,8 +1637,25 @@ Scholar.ItemTypes = new function(){ } function getTypeName(itemTypeID){ - return Scholar.DB.valueQuery('SELECT typeName FROM itemTypes ' - + 'WHERE itemTypeID=' + itemTypeID); + if (!_itemTypesLoaded){ + _load(); + } + + if (!_itemTypes[itemTypeID]){ + Scholar.debug('Invalid item type ' + itemTypeID, 1); + } + + return _itemTypes[itemTypeID]; + } + + function _load(){ + var types = self.getTypes(); + + for (i in types){ + _itemTypes[types[i]['id']] = types[i]['name']; + } + + _itemTypesLoaded = true; } }