Cache item type names to prevent repeated DB lookups in ItemTypes.getTypeName()
This commit is contained in:
parent
b1389bfc61
commit
5a045f5b50
|
@ -1624,6 +1624,10 @@ Scholar.Creators = new function(){
|
||||||
|
|
||||||
|
|
||||||
Scholar.ItemTypes = new function(){
|
Scholar.ItemTypes = new function(){
|
||||||
|
var _itemTypes = new Array();
|
||||||
|
var _itemTypesLoaded;
|
||||||
|
var self = this;
|
||||||
|
|
||||||
this.getTypes = getTypes;
|
this.getTypes = getTypes;
|
||||||
this.getTypeName = getTypeName;
|
this.getTypeName = getTypeName;
|
||||||
|
|
||||||
|
@ -1633,8 +1637,25 @@ Scholar.ItemTypes = new function(){
|
||||||
}
|
}
|
||||||
|
|
||||||
function getTypeName(itemTypeID){
|
function getTypeName(itemTypeID){
|
||||||
return Scholar.DB.valueQuery('SELECT typeName FROM itemTypes '
|
if (!_itemTypesLoaded){
|
||||||
+ 'WHERE itemTypeID=' + itemTypeID);
|
_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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user