Optimize model upsert, ensure right type for roles

This commit is contained in:
miruka
2019-07-04 18:37:15 -04:00
parent 6b83d79f16
commit 07438150db
8 changed files with 65 additions and 44 deletions

View File

@@ -81,10 +81,24 @@ SortFilterProxyModel {
return model.get(model.count)
}
if (update_if_exist != false) {
model.set(indices[0], new_item)
}
return model.get(indices[0])
var existing = model.get(indices[0])
if (update_if_exist == false) { return existing }
// Really update only if existing and new item have a difference
for (var role in existing) {
if (Boolean(existing[role].getTime)) {
if (existing[role].getTime() != new_item[role].getTime()) {
model.set(indices[0], new_item)
return existing
}
} else {
if (existing[role] != new_item[role]) {
model.set(indices[0], new_item)
return existing
}
}
}
return existing
}
function pop(index) {