Skip to content

Commit

Permalink
[Scrub.c] 8628ca8 rewritten to avoid QofQuery
Browse files Browse the repository at this point in the history
because QofQuery will include the blank transaction which must not be
scrubbed.
  • Loading branch information
christopherlam committed Jun 12, 2023
1 parent 6d60c11 commit 8ec6a4c
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions libgnucash/engine/Scrub.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@
#include "gnc-commodity.h"
#include "qofinstance-p.h"
#include "gnc-session.h"
#include "qofquery.h"
#include "Query.h"

#undef G_LOG_DOMAIN
#define G_LOG_DOMAIN "gnc.engine.scrub"
Expand Down Expand Up @@ -91,18 +89,22 @@ gnc_get_ongoing_scrub (void)

/* ================================================================ */

static void add_transactions (const Account *account, GHashTable **ht)
{
for (GList *m = xaccAccountGetSplitList (account); m; m = g_list_next (m))
g_hash_table_add (*ht, xaccSplitGetParent (m->data));
}

static GList*
get_all_transactions (Account *account, bool descendants)
{
GList *accounts = descendants ? gnc_account_get_descendants (account) : NULL;
accounts = g_list_prepend (accounts, account);
QofQuery *q = qof_query_create_for (GNC_ID_TRANS);
QofBook *book = qof_session_get_book (gnc_get_current_session ());
qof_query_set_book (q, book);
xaccQueryAddAccountMatch (q, accounts, QOF_GUID_MATCH_ANY, QOF_QUERY_AND);
GList *transactions = g_list_copy (qof_query_run (q));
qof_query_destroy (q);
return transactions;
GHashTable *ht = g_hash_table_new (g_direct_hash, g_direct_equal);
add_transactions (account, &ht);
if (descendants)
gnc_account_foreach_descendant (account, (AccountCb)add_transactions, &ht);
GList *rv = g_hash_table_get_keys (ht);
g_hash_table_destroy (ht);
return rv;
}

/* ================================================================ */
Expand Down

0 comments on commit 8ec6a4c

Please sign in to comment.