commit c24c148e0b30552a52a15d73cf7e419dff2c0883 parent 5a045f5b50fe2fc77963019c33a585c399794beb Author: Dan Stillman <dstillman@zotero.org> Date: Mon, 12 Jun 2006 13:05:30 +0000 Cache creator type names to prevent repeated DB lookups in CreatorTypes.getTypeName() Diffstat:
| M | chrome/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 @@ -1816,6 +1816,10 @@ Scholar.ItemFields = new function(){ Scholar.CreatorTypes = new function(){ + var _creatorTypes = new Array(); + var _creatorTypesLoaded; + var self = this; + this.getTypes = getTypes; this.getTypeName = getTypeName; @@ -1825,8 +1829,25 @@ Scholar.CreatorTypes = new function(){ } function getTypeName(creatorTypeID){ - return Scholar.DB.valueQuery('SELECT creatorType FROM creatorTypes ' - + 'WHERE creatorTypeID=' + creatorTypeID); + if (!_creatorTypesLoaded){ + _load(); + } + + if (!_creatorTypes[creatorTypeID]){ + Scholar.debug('Invalid creator type ' + creatorTypeID, 1); + } + + return _creatorTypes[creatorTypeID]; + } + + function _load(){ + var types = self.getTypes(); + + for (i in types){ + _creatorTypes[types[i]['id']] = types[i]['name']; + } + + _creatorTypesLoaded = true; } }