From 82d891a202f77c8550f9f548639f6f9de240d046 Mon Sep 17 00:00:00 2001 From: John Ralls Date: Sun, 20 Aug 2017 21:24:02 +0200 Subject: [PATCH] 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. --- libgnucash/engine/qofbook.cpp | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/libgnucash/engine/qofbook.cpp b/libgnucash/engine/qofbook.cpp index 1b2dfd6035..b37ecd7d8f 100644 --- a/libgnucash/engine/qofbook.cpp +++ b/libgnucash/engine/qofbook.cpp @@ -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(); + feature = feature_frame->get_slot(key); + } + if (feature == nullptr || g_strcmp0 (feature->get(), 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