gnucash master: Multiple changes pushed

Christopher Lam clam at code.gnucash.org
Thu May 14 08:43:38 EDT 2020


Updated	 via  https://github.com/Gnucash/gnucash/commit/09a8bee5 (commit)
	 via  https://github.com/Gnucash/gnucash/commit/8ea9e411 (commit)
	 via  https://github.com/Gnucash/gnucash/commit/a3dae3bd (commit)
	from  https://github.com/Gnucash/gnucash/commit/ecf429a4 (commit)



commit 09a8bee5c0a38dbd8bee9d3d1185f1d54df5b34e
Merge: 8ea9e4119 a3dae3bd4
Author: Christopher Lam <christopher.lck at gmail.com>
Date:   Thu May 14 20:30:08 2020 +0800

    Merge branch 'speedup-aging' #638


commit 8ea9e411904d12c7f83ebb0752e7b3424f9867bd
Author: Christopher Lam <christopher.lck at gmail.com>
Date:   Thu May 14 19:47:07 2020 +0800

    [register] display $0.00 for zero-value splits

diff --git a/gnucash/report/reports/standard/register.scm b/gnucash/report/reports/standard/register.scm
index ed2c807be..080fa759b 100644
--- a/gnucash/report/reports/standard/register.scm
+++ b/gnucash/report/reports/standard/register.scm
@@ -265,7 +265,7 @@
                         " "))
             (addto! row-contents " ")))
     (if (credit-col column-vector)
-        (if (negative? (gnc:gnc-monetary-amount split-value))
+        (if (not (positive? (gnc:gnc-monetary-amount split-value)))
             (addto! row-contents
                     (if split-info?
                         (gnc:make-html-table-cell/markup
diff --git a/gnucash/report/reports/standard/test/test-register.scm b/gnucash/report/reports/standard/test/test-register.scm
index 86d561e15..eb3967a73 100644
--- a/gnucash/report/reports/standard/test/test-register.scm
+++ b/gnucash/report/reports/standard/test/test-register.scm
@@ -66,8 +66,8 @@
       (set-option options "__reg" "query" (gnc-query2scm query)))
 
     (let ((sxml (options->sxml options "basic")))
-      (test-equal "table has 231 cells"
-        231
+      (test-equal "table has 232 cells"
+        232
         (length (sxml->table-row-col sxml 1 #f #f)))
 
       (test-equal "total debit = $2587"
@@ -80,8 +80,8 @@
 
     (set-option options "__reg" "journal" #t)
     (let ((sxml (options->sxml options "journal")))
-      (test-equal "table has 337 cells"
-        337
+      (test-equal "table has 339 cells"
+        339
         (length (sxml->table-row-col sxml 1 #f #f)))
 
       (test-equal "total debit = #6"
@@ -102,8 +102,8 @@
 
     (set-option options "__reg" "ledger-type" #t)
     (let ((sxml (options->sxml options "ledger-type")))
-      (test-equal "table has 341 cells"
-        341
+      (test-equal "table has 343 cells"
+        343
         (length (sxml->table-row-col sxml 1 #f #f)))
 
       (test-equal "total debit = #6"
@@ -132,8 +132,8 @@
 
     (set-option options "__reg" "double" #t)
     (let ((sxml (options->sxml options "double")))
-      (test-equal "table has 345 cells"
-        345
+      (test-equal "table has 347 cells"
+        347
         (length (sxml->table-row-col sxml 1 #f #f)))
 
       (test-equal "total debit = #6"

commit a3dae3bd4dea908b9e90e49f02e241d765ba2996
Author: Christopher Lam <christopher.lck at gmail.com>
Date:   Mon Jan 20 23:20:57 2020 +0800

    [gnc-lot.c] speed up gncInvoiceGetInvoiceFromLot by caching invoice

diff --git a/libgnucash/engine/gnc-lot.c b/libgnucash/engine/gnc-lot.c
index 7aac38de6..2ed6baafb 100644
--- a/libgnucash/engine/gnc-lot.c
+++ b/libgnucash/engine/gnc-lot.c
@@ -52,6 +52,7 @@
 #include "cap-gains.h"
 #include "Transaction.h"
 #include "TransactionP.h"
+#include "gncInvoice.h"
 
 /* This static indicates the debugging module that this .o belongs to.  */
 static QofLogModule log_module = GNC_MOD_LOT;
@@ -85,6 +86,7 @@ typedef struct GNCLotPrivate
     /* List of splits that belong to this lot. */
     SplitList *splits;
 
+    GncInvoice *cached_invoice;
     /* Handy cached value to indicate if lot is closed. */
     /* If value is negative, then the cache is invalid. */
     signed char is_closed;
@@ -112,6 +114,7 @@ gnc_lot_init(GNCLot* lot)
     priv = GET_PRIVATE(lot);
     priv->account = NULL;
     priv->splits = NULL;
+    priv->cached_invoice = NULL;
     priv->is_closed = LOT_CLOSED_UNKNOWN;
     priv->marker = 0;
 }
@@ -378,6 +381,19 @@ gnc_lot_get_account (const GNCLot *lot)
     return priv->account;
 }
 
+GncInvoice * gnc_lot_get_cached_invoice (const GNCLot *lot)
+{
+    if (!lot) return NULL;
+    return GET_PRIVATE(lot)->cached_invoice;
+}
+
+void
+gnc_lot_set_cached_invoice(GNCLot* lot, GncInvoice *invoice)
+{
+    if (!lot) return;
+    GET_PRIVATE(lot)->cached_invoice = invoice;
+}
+
 void
 gnc_lot_set_account(GNCLot* lot, Account* account)
 {
diff --git a/libgnucash/engine/gnc-lot.h b/libgnucash/engine/gnc-lot.h
index bbebdb791..3ea131fa8 100644
--- a/libgnucash/engine/gnc-lot.h
+++ b/libgnucash/engine/gnc-lot.h
@@ -64,6 +64,7 @@
 #include "qof.h"
 #include "gnc-engine.h"
 /*#include "gnc-lot-p.h"*/
+#include "gncInvoice.h"
 
 #ifdef __cplusplus
 extern "C" {
@@ -127,6 +128,12 @@ gint gnc_lot_count_splits (const GNCLot *);
 Account * gnc_lot_get_account (const GNCLot *);
 void gnc_lot_set_account(GNCLot*, Account*);
 
+/** The gnc_lot_get_cached_invoice() routine returns the invoice with
+ *    which this lot is associated. */
+/*@ dependent @*/
+GncInvoice * gnc_lot_get_cached_invoice (const GNCLot *lot);
+void gnc_lot_set_cached_invoice(GNCLot* lot, GncInvoice *invoice);
+
 /** The gnc_lot_get_balance() routine returns the balance of the lot.
  *    The commodity in which this balance is expressed is the commodity
  *    of the account. */
diff --git a/libgnucash/engine/gncInvoice.c b/libgnucash/engine/gncInvoice.c
index 9ad48692c..9389c70d1 100644
--- a/libgnucash/engine/gncInvoice.c
+++ b/libgnucash/engine/gncInvoice.c
@@ -1228,6 +1228,7 @@ gncInvoiceDetachFromLot (GNCLot *lot)
     gnc_lot_begin_edit (lot);
     qof_instance_set (QOF_INSTANCE (lot), "invoice", NULL, NULL);
     gnc_lot_commit_edit (lot);
+    gnc_lot_set_cached_invoice (lot, NULL);
 }
 
 void
@@ -1242,6 +1243,7 @@ gncInvoiceAttachToLot (GncInvoice *invoice, GNCLot *lot)
     gnc_lot_begin_edit (lot);
     qof_instance_set (QOF_INSTANCE (lot), "invoice", guid, NULL);
     gnc_lot_commit_edit (lot);
+    gnc_lot_set_cached_invoice (lot, invoice);
     gncInvoiceSetPostedLot (invoice, lot);
 }
 
@@ -1253,10 +1255,16 @@ GncInvoice * gncInvoiceGetInvoiceFromLot (GNCLot *lot)
 
     if (!lot) return NULL;
 
-    book = gnc_lot_get_book (lot);
-    qof_instance_get (QOF_INSTANCE (lot), "invoice", &guid, NULL);
-    invoice = gncInvoiceLookup(book, guid);
-    guid_free (guid);
+    invoice = gnc_lot_get_cached_invoice (lot);
+    if (!invoice)
+    {
+        book = gnc_lot_get_book (lot);
+        qof_instance_get (QOF_INSTANCE (lot), "invoice", &guid, NULL);
+        invoice = gncInvoiceLookup(book, guid);
+        guid_free (guid);
+        gnc_lot_set_cached_invoice (lot, invoice);
+    }
+
     return invoice;
 }
 



Summary of changes:
 gnucash/report/reports/standard/register.scm           |  2 +-
 gnucash/report/reports/standard/test/test-register.scm | 16 ++++++++--------
 libgnucash/engine/gnc-lot.c                            | 16 ++++++++++++++++
 libgnucash/engine/gnc-lot.h                            |  7 +++++++
 libgnucash/engine/gncInvoice.c                         | 16 ++++++++++++----
 5 files changed, 44 insertions(+), 13 deletions(-)



More information about the gnucash-changes mailing list