commit 30b389823523c5c0f7019733e11ff69461e1ce4b
parent b1a51f900d5a8e48590fd87807da285a31768fa2
Author: Simon Kornblith <simon@simonster.com>
Date: Sun, 22 Jul 2012 20:13:40 -0400
Closes #148, Optimize Zotero.Item.getSource()
Diffstat:
2 files changed, 7 insertions(+), 2 deletions(-)
diff --git a/chrome/content/zotero/xpcom/data/item.js b/chrome/content/zotero/xpcom/data/item.js
@@ -402,6 +402,9 @@ Zotero.Item.prototype.loadFromRow = function(row, reload) {
this['_' + col] = row[col] ? parseInt(row[col]) : 0;
break;
+ case 'sourceItemID':
+ this['_sourceItem'] = row[col] || false;
+
default:
this['_' + col] = row[col] ? row[col] : '';
}
diff --git a/chrome/content/zotero/xpcom/data/items.js b/chrome/content/zotero/xpcom/data/items.js
@@ -46,7 +46,7 @@ Zotero.Items = new function() {
_primaryFields = Zotero.DB.getColumns('items');
_primaryFields.splice(_primaryFields.indexOf('clientDateModified'), 1);
_primaryFields = _primaryFields.concat(
- ['firstCreator', 'numNotes', 'numAttachments']
+ ['firstCreator', 'numNotes', 'numAttachments', 'sourceItemID']
);
}
@@ -749,7 +749,9 @@ Zotero.Items = new function() {
+ "(SELECT COUNT(*) FROM itemNotes INo WHERE sourceItemID=I.itemID AND "
+ "INo.itemID NOT IN (SELECT itemID FROM deletedItems)) AS numNotes, "
+ "(SELECT COUNT(*) FROM itemAttachments IA WHERE sourceItemID=I.itemID AND "
- + "IA.itemID NOT IN (SELECT itemID FROM deletedItems)) AS numAttachments "
+ + "IA.itemID NOT IN (SELECT itemID FROM deletedItems)) AS numAttachments, "
+ + "(CASE I.itemTypeID WHEN 14 THEN (SELECT sourceItemID FROM itemAttachments IA WHERE IA.itemID=I.itemID) "
+ + "WHEN 1 THEN (SELECT sourceItemID FROM itemNotes INo WHERE INo.itemID=I.itemID) END) AS sourceItemID "
+ 'FROM items I WHERE 1';
if (arguments[0]) {
sql += ' AND I.itemID IN (' + Zotero.join(arguments[0], ',') + ')';