mirror of
https://github.com/Gnucash/gnucash.git
synced 2024-12-02 05:29:20 -06:00
[report-utilities] improve (gnc:account-get-comm-value-interval)
This commit will marginally speed up this function when include-children? is #t. The original code would create a new query for each descendant. This commit will create one query only for all accounts when include-children? is #t. Unfortunately there is no actual live code whereby include-children? is enabled. Anyway this code is cleaned up.
This commit is contained in:
parent
984501e951
commit
77063afa73
@ -413,41 +413,35 @@ construct gnc:make-gnc-monetary and use gnc:monetary->string instead.")
|
||||
;; just direct children) are are included in the calculation. The results
|
||||
;; are returned in a commodity collector.
|
||||
(define (gnc:account-get-comm-value-interval account start-date end-date
|
||||
include-children?)
|
||||
include-children?)
|
||||
(let ((value-collector (gnc:make-commodity-collector))
|
||||
(query (qof-query-create-for-splits))
|
||||
(splits #f))
|
||||
|
||||
(if include-children?
|
||||
(for-each
|
||||
(lambda (x)
|
||||
(value-collector 'merge x #f))
|
||||
(gnc:account-map-descendants
|
||||
(lambda (d)
|
||||
(gnc:account-get-comm-value-interval d start-date end-date #f))
|
||||
account)))
|
||||
(query (qof-query-create-for-splits))
|
||||
(accounts (cons account
|
||||
(if include-children?
|
||||
(gnc-account-get-descendants account)
|
||||
'()))))
|
||||
|
||||
;; Build a query to find all splits between the indicated dates.
|
||||
(qof-query-set-book query (gnc-get-current-book))
|
||||
(xaccQueryAddSingleAccountMatch query account QOF-QUERY-AND)
|
||||
(xaccQueryAddAccountMatch query accounts
|
||||
QOF-GUID-MATCH-ANY
|
||||
QOF-QUERY-AND)
|
||||
(xaccQueryAddDateMatchTT query
|
||||
(and start-date #t) (if start-date start-date 0)
|
||||
(and end-date #t) (if end-date end-date 0)
|
||||
(and start-date #t) (or start-date 0)
|
||||
(and end-date #t) (or end-date 0)
|
||||
QOF-QUERY-AND)
|
||||
|
||||
;; Get the query results.
|
||||
(set! splits (qof-query-run query))
|
||||
(qof-query-destroy query)
|
||||
|
||||
;; Add the "value" of each split returned (which is measured
|
||||
;; in the transaction currency).
|
||||
(for-each
|
||||
(lambda (split)
|
||||
(value-collector 'add
|
||||
(xaccTransGetCurrency (xaccSplitGetParent split))
|
||||
(xaccSplitGetValue split)))
|
||||
splits)
|
||||
|
||||
(let ((splits (qof-query-run query)))
|
||||
(qof-query-destroy query)
|
||||
;; Add the "value" of each split returned (which is measured
|
||||
;; in the transaction currency).
|
||||
(for-each
|
||||
(lambda (split)
|
||||
(value-collector 'add
|
||||
(xaccTransGetCurrency (xaccSplitGetParent split))
|
||||
(xaccSplitGetValue split)))
|
||||
splits))
|
||||
value-collector))
|
||||
|
||||
;; Calculate the balance of the account in terms of "value" (rather
|
||||
|
Loading…
Reference in New Issue
Block a user