Test features to see if they're already set before setting them.

Setting a feature writes to KVP which in the SQL backend causes the book
to be written out, which is rather expensive. Doing this in a loop (as
is the case in convert_imap_account, is quite slow, and this change
afforded a 4x speedup.
This commit is contained in:
John Ralls 2017-08-20 21:24:02 +02:00
parent 4fc61b2ac8
commit 82d891a202

View File

@ -1144,10 +1144,20 @@ void
qof_book_set_feature (QofBook *book, const gchar *key, const gchar *descr)
{
KvpFrame *frame = qof_instance_get_slots (QOF_INSTANCE (book));
qof_book_begin_edit (book);
delete frame->set_path({GNC_FEATURES, key}, new KvpValue(descr));
qof_instance_set_dirty (QOF_INSTANCE (book));
qof_book_commit_edit (book);
KvpValue* feature = nullptr;
auto feature_slot = frame->get_slot(GNC_FEATURES);
if (feature_slot)
{
auto feature_frame = feature_slot->get<KvpFrame*>();
feature = feature_frame->get_slot(key);
}
if (feature == nullptr || g_strcmp0 (feature->get<const char*>(), descr))
{
qof_book_begin_edit (book);
delete frame->set_path({GNC_FEATURES, key}, new KvpValue(descr));
qof_instance_set_dirty (QOF_INSTANCE (book));
qof_book_commit_edit (book);
}
}
void