Speed up comparison of items with huge numbers of tags

Can cause a freeze while syncing items with 1000s of tags
This commit is contained in:
Dan Stillman 2022-03-01 02:43:58 -05:00
parent b7f26c47c1
commit a10fcfd58e
2 changed files with 12 additions and 5 deletions

View file

@ -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;
}
}

View file

@ -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);
},