Cache creator type names to prevent repeated DB lookups in CreatorTypes.getTypeName()
This commit is contained in:
parent
5a045f5b50
commit
c24c148e0b
|
@ -1816,6 +1816,10 @@ Scholar.ItemFields = new function(){
|
||||||
|
|
||||||
|
|
||||||
Scholar.CreatorTypes = new function(){
|
Scholar.CreatorTypes = new function(){
|
||||||
|
var _creatorTypes = new Array();
|
||||||
|
var _creatorTypesLoaded;
|
||||||
|
var self = this;
|
||||||
|
|
||||||
this.getTypes = getTypes;
|
this.getTypes = getTypes;
|
||||||
this.getTypeName = getTypeName;
|
this.getTypeName = getTypeName;
|
||||||
|
|
||||||
|
@ -1825,8 +1829,25 @@ Scholar.CreatorTypes = new function(){
|
||||||
}
|
}
|
||||||
|
|
||||||
function getTypeName(creatorTypeID){
|
function getTypeName(creatorTypeID){
|
||||||
return Scholar.DB.valueQuery('SELECT creatorType FROM creatorTypes '
|
if (!_creatorTypesLoaded){
|
||||||
+ 'WHERE creatorTypeID=' + creatorTypeID);
|
_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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user