From 30b389823523c5c0f7019733e11ff69461e1ce4b Mon Sep 17 00:00:00 2001 From: Simon Kornblith Date: Sun, 22 Jul 2012 20:13:40 -0400 Subject: [PATCH] Closes #148, Optimize Zotero.Item.getSource() --- chrome/content/zotero/xpcom/data/item.js | 3 +++ chrome/content/zotero/xpcom/data/items.js | 6 ++++-- 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 index fd26904cf..04988c1cd 100644 --- 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 index cca97c184..8116c041e 100644 --- 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], ',') + ')';