From a10fcfd58e3a497bbddf3b17fcffe43ac0f1ea4e Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Tue, 1 Mar 2022 02:43:58 -0500 Subject: [PATCH] Speed up comparison of items with huge numbers of tags Can cause a freeze while syncing items with 1000s of tags --- chrome/content/zotero/xpcom/data/dataObjectUtilities.js | 9 +++++++-- chrome/content/zotero/xpcom/data/tags.js | 8 +++++--- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/chrome/content/zotero/xpcom/data/dataObjectUtilities.js b/chrome/content/zotero/xpcom/data/dataObjectUtilities.js index 1f3ca4717d..7e0ca16e37 100644 --- a/chrome/content/zotero/xpcom/data/dataObjectUtilities.js +++ b/chrome/content/zotero/xpcom/data/dataObjectUtilities.js @@ -505,11 +505,16 @@ Zotero.DataObjectUtilities = { }, _tagsDiff: function (data1, data2 = []) { + var equals = Zotero.Tags.equals.bind(Zotero.Tags); + + var cleanedData1 = data1.map(x => Zotero.Tags.cleanData(x)); + var cleanedData2 = data2.map(x => Zotero.Tags.cleanData(x)); + var changeset = []; outer: for (let i = 0; i < data1.length; i++) { for (let j = 0; j < data2.length; j++) { - if (Zotero.Tags.equals(data1[i], data2[j])) { + if (equals(cleanedData1[i], cleanedData2[j], { skipClean: true })) { continue outer; } } @@ -522,7 +527,7 @@ Zotero.DataObjectUtilities = { outer: for (let i = 0; i < data2.length; i++) { for (let j = 0; j < data1.length; j++) { - if (Zotero.Tags.equals(data2[i], data1[j])) { + if (equals(cleanedData2[i], cleanedData1[j], { skipClean: true })) { continue outer; } } diff --git a/chrome/content/zotero/xpcom/data/tags.js b/chrome/content/zotero/xpcom/data/tags.js index 1324c44407..385341e7ce 100644 --- a/chrome/content/zotero/xpcom/data/tags.js +++ b/chrome/content/zotero/xpcom/data/tags.js @@ -944,9 +944,11 @@ Zotero.Tags = new function() { /** * Compare two API JSON tag objects */ - this.equals = function (data1, data2) { - data1 = this.cleanData(data1); - data2 = this.cleanData(data2); + this.equals = function (data1, data2, options = {}) { + if (!options.skipClean) { + data1 = this.cleanData(data1); + data2 = this.cleanData(data2); + } return data1.tag === data2.tag && ((!data1.type && !data2.type) || data1.type === data2.type); },