gnucash maint: Multiple changes pushed

Geert Janssens gjanssens at code.gnucash.org
Sat Sep 15 13:14:10 EDT 2018


Updated	 via  https://github.com/Gnucash/gnucash/commit/5057703d (commit)
	 via  https://github.com/Gnucash/gnucash/commit/5775662b (commit)
	 via  https://github.com/Gnucash/gnucash/commit/221c4658 (commit)
	from  https://github.com/Gnucash/gnucash/commit/5609b704 (commit)



commit 5057703d30e1953b31587ca6c54f16c8faa983de
Author: Geert Janssens <geert at kobaltwit.be>
Date:   Sat Sep 15 17:48:37 2018 +0200

    Sql backend - show progress similar to how it's done for xml backend
    
    That is let the percentage increase gradually. The current granularity is still
    very rough, but at least it gives an indication of getting closer to fully
    loading the data. The previous configuration on the other hand only suggested
    something was happening but with no indication where in the load process
    gnucash was.

diff --git a/libgnucash/backend/sql/gnc-sql-backend.cpp b/libgnucash/backend/sql/gnc-sql-backend.cpp
index 8b9108c..3e31d4c 100644
--- a/libgnucash/backend/sql/gnc-sql-backend.cpp
+++ b/libgnucash/backend/sql/gnc-sql-backend.cpp
@@ -184,10 +184,10 @@ GncSqlBackend::add_columns_to_table(const std::string& table_name,
 }
 
 void
-GncSqlBackend::update_progress() const noexcept
+GncSqlBackend::update_progress(double pct) const noexcept
 {
     if (m_percentage != nullptr)
-        (m_percentage) (nullptr, 101.0);
+        (m_percentage) (nullptr, pct);
 }
 
 void
@@ -202,7 +202,7 @@ GncSqlBackend::create_tables() noexcept
 {
     for(auto entry : m_backend_registry)
     {
-        update_progress();
+        update_progress(101.0);
         std::get<1>(entry)->create_tables(this);
     }
 }
@@ -219,6 +219,9 @@ void
 GncSqlBackend::ObjectBackendRegistry::load_remaining(GncSqlBackend* sql_be)
 {
 
+    auto num_types = m_registry.size();
+    auto num_done = fixed_load_order.size() + business_fixed_load_order.size();
+
     for (auto entry : m_registry)
     {
         std::string type;
@@ -234,6 +237,8 @@ GncSqlBackend::ObjectBackendRegistry::load_remaining(GncSqlBackend* sql_be)
                       business_fixed_load_order.end(),
                       type) != business_fixed_load_order.end()) continue;
 
+        num_done++;
+        sql_be->update_progress(num_done * 100 / num_types);
         obe->load_all (sql_be);
     }
 }
@@ -273,22 +278,27 @@ GncSqlBackend::load (QofBook* book, QofBackendLoadType loadType)
         assert (m_book == nullptr);
         m_book = book;
 
+        auto num_types = m_backend_registry.size();
+        auto num_done = 0;
+
         /* Load any initial stuff. Some of this needs to happen in a certain order */
         for (auto type : fixed_load_order)
         {
+            num_done++;
             auto obe = m_backend_registry.get_object_backend(type);
             if (obe)
             {
-                update_progress();
+                update_progress(num_done * 100 / num_types);
                 obe->load_all(this);
             }
         }
         for (auto type : business_fixed_load_order)
         {
+            num_done++;
             auto obe = m_backend_registry.get_object_backend(type);
             if (obe)
             {
-                update_progress();
+                update_progress(num_done * 100 / num_types);
                 obe->load_all(this);
             }
         }
@@ -349,7 +359,7 @@ GncSqlBackend::write_account_tree(Account* root)
         }
         g_list_free (descendants);
     }
-    update_progress();
+    update_progress(101.0);
 
     return is_ok;
 }
@@ -357,11 +367,11 @@ GncSqlBackend::write_account_tree(Account* root)
 bool
 GncSqlBackend::write_accounts()
 {
-    update_progress();
+    update_progress(101.0);
     auto is_ok = write_account_tree (gnc_book_get_root_account (m_book));
     if (is_ok)
     {
-        update_progress();
+        update_progress(101.0);
         is_ok = write_account_tree (gnc_book_get_template_root(m_book));
     }
 
@@ -384,7 +394,7 @@ write_tx (Transaction* tx, gpointer data)
     {
         s->is_ok = splitbe->commit(s->be, QOF_INSTANCE(split_node->data));
     }
-    s->be->update_progress ();
+    s->be->update_progress (101.0);
     return (s->is_ok ? 0 : 1);
 }
 
@@ -396,7 +406,7 @@ GncSqlBackend::write_transactions()
 
     (void)xaccAccountTreeForEachTransaction (
         gnc_book_get_root_account (m_book), write_tx, &data);
-    update_progress();
+    update_progress(101.0);
     return data.is_ok;
 }
 
@@ -409,7 +419,7 @@ GncSqlBackend::write_template_transactions()
     if (gnc_account_n_descendants (ra) > 0)
     {
         (void)xaccAccountTreeForEachTransaction (ra, write_tx, &data);
-        update_progress();
+        update_progress(101.0);
     }
 
     return data.is_ok;
@@ -430,7 +440,7 @@ GncSqlBackend::write_schedXactions()
         tmpSX = static_cast<decltype (tmpSX)> (schedXactions->data);
         is_ok = obe->commit (this, QOF_INSTANCE (tmpSX));
     }
-    update_progress();
+    update_progress(101.0);
 
     return is_ok;
 }
@@ -444,7 +454,7 @@ GncSqlBackend::sync(QofBook* book)
 
     reset_version_info();
     ENTER ("book=%p, sql_be->book=%p", book, m_book);
-    update_progress();
+    update_progress(101.0);
 
     /* Create new tables */
     m_is_pristine_db = true;
diff --git a/libgnucash/backend/sql/gnc-sql-backend.hpp b/libgnucash/backend/sql/gnc-sql-backend.hpp
index 051b3ed..4423ccb 100644
--- a/libgnucash/backend/sql/gnc-sql-backend.hpp
+++ b/libgnucash/backend/sql/gnc-sql-backend.hpp
@@ -237,7 +237,7 @@ public:
     QofBook* book() const noexcept { return m_book; }
     void set_loading(bool loading) noexcept { m_loading = loading; }
     bool pristine() const noexcept { return m_is_pristine_db; }
-    void update_progress() const noexcept;
+    void update_progress(double pct) const noexcept;
     void finish_progress() const noexcept;
 
 protected:
@@ -282,6 +282,7 @@ private:
         void load_remaining(GncSqlBackend*);
         OBEVec::iterator begin() { return m_registry.begin(); }
         OBEVec::iterator end() { return m_registry.end(); }
+        OBEVec::size_type size() { return m_registry.size(); }
     private:
         OBEVec m_registry;
     };

commit 5775662b52869604913a44972737cd8748945169
Author: Geert Janssens <geert at kobaltwit.be>
Date:   Sat Sep 15 16:41:37 2018 +0200

    Raise edit level of all accounts before loading transactions and splits
    
    This prevents calling xaccAccountRecomputeBalanceInCurrency on each split that gets added,
    which was exponentially increasing load times. On a huge test book the
    load time dropped from 53 minutes to 1m20s.

diff --git a/libgnucash/backend/sql/gnc-transaction-sql.cpp b/libgnucash/backend/sql/gnc-transaction-sql.cpp
index 780cfcf..7fa0f94 100644
--- a/libgnucash/backend/sql/gnc-transaction-sql.cpp
+++ b/libgnucash/backend/sql/gnc-transaction-sql.cpp
@@ -714,7 +714,13 @@ void
 GncSqlTransBackend::load_all (GncSqlBackend* sql_be)
 {
     g_return_if_fail (sql_be != NULL);
+
+    auto root = gnc_book_get_root_account (sql_be->book());;
+    gnc_account_foreach_descendant(root, (AccountCb)xaccAccountBeginEdit,
+                                   nullptr);
     query_transactions (sql_be, "");
+    gnc_account_foreach_descendant(root, (AccountCb)xaccAccountCommitEdit,
+                                   nullptr);
 }
 
 static void

commit 221c46585c53ee7f0bdf388347f952426866149c
Author: Geert Janssens <geert at kobaltwit.be>
Date:   Sat Sep 15 16:38:55 2018 +0200

    Sql backend - load transactions before business objects to reduce individual slot queries

diff --git a/libgnucash/backend/sql/gnc-sql-backend.cpp b/libgnucash/backend/sql/gnc-sql-backend.cpp
index 536b76b..8b9108c 100644
--- a/libgnucash/backend/sql/gnc-sql-backend.cpp
+++ b/libgnucash/backend/sql/gnc-sql-backend.cpp
@@ -209,7 +209,7 @@ GncSqlBackend::create_tables() noexcept
 
 /* Main object load order */
 static const StrVec fixed_load_order
-{ GNC_ID_BOOK, GNC_ID_COMMODITY, GNC_ID_ACCOUNT, GNC_ID_LOT };
+{ GNC_ID_BOOK, GNC_ID_COMMODITY, GNC_ID_ACCOUNT, GNC_ID_LOT, GNC_ID_TRANS };
 
 /* Order in which business objects need to be loaded */
 static const StrVec business_fixed_load_order =



Summary of changes:
 libgnucash/backend/sql/gnc-sql-backend.cpp     | 38 ++++++++++++++++----------
 libgnucash/backend/sql/gnc-sql-backend.hpp     |  3 +-
 libgnucash/backend/sql/gnc-transaction-sql.cpp |  6 ++++
 3 files changed, 32 insertions(+), 15 deletions(-)



More information about the gnucash-changes mailing list