commit d55f8748812b83fc810cb1ac12ddf9bdf71b544f
parent 6dbc6556bda4ff3a071c8f050999bdc1879209f8
Author: Dan Stillman <dstillman@zotero.org>
Date: Tue, 21 Jul 2009 21:51:34 +0000
Cache Zotero.CreatorTypes.getPrimaryIDForType()
Diffstat:
1 file changed, 11 insertions(+), 1 deletion(-)
diff --git a/chrome/content/zotero/xpcom/data/cachedTypes.js b/chrome/content/zotero/xpcom/data/cachedTypes.js
@@ -136,6 +136,8 @@ Zotero.CreatorTypes = new function() {
this._nameCol = 'creatorType';
this._table = 'creatorTypes';
+ var _primaryIDCache = {};
+
function getTypesForItemType(itemTypeID) {
var sql = "SELECT creatorTypeID AS id, creatorType AS name "
+ "FROM itemTypeCreatorTypes NATURAL JOIN creatorTypes "
@@ -154,9 +156,17 @@ Zotero.CreatorTypes = new function() {
function getPrimaryIDForType(itemTypeID) {
+ if (_primaryIDCache[itemTypeID]) {
+ return _primaryIDCache[itemTypeID];
+ }
var sql = "SELECT creatorTypeID FROM itemTypeCreatorTypes "
+ "WHERE itemTypeID=? AND primaryField=1";
- return Zotero.DB.valueQuery(sql, itemTypeID);
+ var creatorTypeID = Zotero.DB.valueQuery(sql, itemTypeID);
+ if (!creatorTypeID) {
+ return false;
+ }
+ _primaryIDCache[itemTypeID] = creatorTypeID;
+ return creatorTypeID;
}
}