From c24c148e0b30552a52a15d73cf7e419dff2c0883 Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Mon, 12 Jun 2006 13:05:30 +0000 Subject: [PATCH] Cache creator type names to prevent repeated DB lookups in CreatorTypes.getTypeName() --- .../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 index d0e0d0d805..d8cce607a8 100644 --- 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; } }