mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
[gnc-ledger-display] Consolidate refresh functions
gnc_ledger_display_gl() is called to create the ledger: 1. Exclude template accounts (unconditionally) 2. Calls gnc_ledger_display_internal() gnc_ledger_display_internal(): 1. Run query 2. Set watches 3. Load splits refresh_handler() is called to refresh all pages when a change happens: 1. Check if the number of subaccounts has changed 2. Exclude any template accounts (for specific register types) 3. Run query 4. Set watches 5. Load splits gnc_ledger_display_refresh() is called by the register plugin: 1. [Doesn't check if the number of subaccounts has changed] 2. Exclude template accounts (for specific register types) 3. Run query 4. Set watches 5. Load splits The last two are inconsistent because they don't both check if the number of subaccounts has changed. Make it easier to conditionally refresh the ledger only when it's visible by consolidating the code from these functions into one place within gnc_ledger_display_refresh() and gnc_ledger_display_refresh_internal().
This commit is contained in:
parent
2c4a096b9c
commit
9ac12db68f
@ -94,8 +94,8 @@ gnc_ledger_display_internal (Account* lead_account, Query* q,
|
||||
gboolean is_template,
|
||||
gboolean mismatched_commodities);
|
||||
|
||||
static void gnc_ledger_display_refresh_internal (GNCLedgerDisplay* ld,
|
||||
GList* splits);
|
||||
static void
|
||||
gnc_ledger_display_refresh_internal (GNCLedgerDisplay* ld);
|
||||
|
||||
static void gnc_ledger_display_make_query (GNCLedgerDisplay* ld,
|
||||
gint limit,
|
||||
@ -584,7 +584,6 @@ refresh_handler (GHashTable* changes, gpointer user_data)
|
||||
GNCLedgerDisplay* ld = user_data;
|
||||
const EventInfo* info;
|
||||
gboolean has_leader;
|
||||
GList* splits;
|
||||
|
||||
ENTER ("changes=%p, user_data=%p", changes, user_data);
|
||||
|
||||
@ -618,35 +617,7 @@ refresh_handler (GHashTable* changes, gpointer user_data)
|
||||
}
|
||||
}
|
||||
|
||||
/* if subaccount ledger, check to see if still the same number
|
||||
* of subaccounts, if not recreate the query. */
|
||||
if (ld->ld_type == LD_SUBACCOUNT)
|
||||
{
|
||||
Account* leader = gnc_ledger_display_leader (ld);
|
||||
GList* accounts = gnc_account_get_descendants (leader);
|
||||
|
||||
if (g_list_length (accounts) != ld->number_of_subaccounts)
|
||||
gnc_ledger_display_make_query (ld,
|
||||
gnc_prefs_get_float (GNC_PREFS_GROUP_GENERAL_REGISTER, GNC_PREF_MAX_TRANS),
|
||||
gnc_get_reg_type (leader, ld->ld_type));
|
||||
|
||||
g_list_free (accounts);
|
||||
}
|
||||
|
||||
// Exclude any template accounts for search register and gl
|
||||
if (!ld->reg->is_template && (ld->reg->type == SEARCH_LEDGER || ld->ld_type == LD_GL))
|
||||
exclude_template_accounts (ld->query, ld->excluded_template_acc_hash);
|
||||
|
||||
/* Its not clear if we should re-run the query, or if we should
|
||||
* just use qof_query_last_run(). Its possible that the dates
|
||||
* changed, requiring a full new query. Similar considerations
|
||||
* needed for multi-user mode.
|
||||
*/
|
||||
splits = qof_query_run (ld->query);
|
||||
|
||||
gnc_ledger_display_set_watches (ld, splits);
|
||||
|
||||
gnc_ledger_display_refresh_internal (ld, splits);
|
||||
gnc_ledger_display_refresh (ld);
|
||||
LEAVE (" ");
|
||||
}
|
||||
|
||||
@ -764,7 +735,6 @@ gnc_ledger_display_internal (Account* lead_account, Query* q,
|
||||
GNCLedgerDisplay* ld;
|
||||
gint limit;
|
||||
const char* klass;
|
||||
GList* splits;
|
||||
|
||||
switch (ld_type)
|
||||
{
|
||||
@ -867,12 +837,10 @@ gnc_ledger_display_internal (Account* lead_account, Query* q,
|
||||
|
||||
gnc_split_register_set_data (ld->reg, ld, gnc_ledger_display_parent);
|
||||
|
||||
splits = qof_query_run (ld->query);
|
||||
|
||||
gnc_ledger_display_set_watches (ld, splits);
|
||||
|
||||
gnc_ledger_display_refresh_internal (ld, splits);
|
||||
|
||||
/* We don't need to recreate the query, so skip that refresh step by
|
||||
* bypassing gnc_ledger_display_refresh().
|
||||
*/
|
||||
gnc_ledger_display_refresh_internal (ld);
|
||||
return ld;
|
||||
}
|
||||
|
||||
@ -902,11 +870,22 @@ gnc_ledger_display_find_by_query (Query* q)
|
||||
\********************************************************************/
|
||||
|
||||
static void
|
||||
gnc_ledger_display_refresh_internal (GNCLedgerDisplay* ld, GList* splits)
|
||||
gnc_ledger_display_refresh_internal (GNCLedgerDisplay* ld)
|
||||
{
|
||||
if (!ld || ld->loading)
|
||||
GList* splits;
|
||||
|
||||
if (ld->loading)
|
||||
return;
|
||||
|
||||
/* It's not clear if we should re-run the query, or if we should
|
||||
* just use qof_query_last_run(). It's possible that the dates
|
||||
* changed, requiring a full new query. Similar considerations
|
||||
* needed for multi-user mode.
|
||||
*/
|
||||
splits = qof_query_run (ld->query);
|
||||
|
||||
gnc_ledger_display_set_watches (ld, splits);
|
||||
|
||||
if (!gnc_split_register_full_refresh_ok (ld->reg))
|
||||
return;
|
||||
|
||||
@ -935,11 +914,32 @@ gnc_ledger_display_refresh (GNCLedgerDisplay* ld)
|
||||
return;
|
||||
}
|
||||
|
||||
/* if subaccount ledger, check to see if still the same number
|
||||
* of subaccounts, if not recreate the query. */
|
||||
if (ld->ld_type == LD_SUBACCOUNT)
|
||||
{
|
||||
Account* leader = gnc_ledger_display_leader (ld);
|
||||
GList* accounts = gnc_account_get_descendants (leader);
|
||||
|
||||
if (g_list_length (accounts) != ld->number_of_subaccounts)
|
||||
gnc_ledger_display_make_query (ld,
|
||||
gnc_prefs_get_float (GNC_PREFS_GROUP_GENERAL_REGISTER, GNC_PREF_MAX_TRANS),
|
||||
gnc_get_reg_type (leader, ld->ld_type));
|
||||
|
||||
g_list_free (accounts);
|
||||
}
|
||||
|
||||
/* In lieu of not "mis-using" some portion of the infrastructure by writing
|
||||
* a bunch of new code, we just filter out the accounts of the template
|
||||
* transactions. While these are in a separate Account trees just for this
|
||||
* reason, the query engine makes no distinction between Account trees.
|
||||
* See Gnome Bug 86302.
|
||||
* -- jsled */
|
||||
// Exclude any template accounts for search register and gl
|
||||
if (!ld->reg->is_template && (ld->reg->type == SEARCH_LEDGER || ld->ld_type == LD_GL))
|
||||
exclude_template_accounts (ld->query, ld->excluded_template_acc_hash);
|
||||
|
||||
gnc_ledger_display_refresh_internal (ld, qof_query_run (ld->query));
|
||||
gnc_ledger_display_refresh_internal (ld);
|
||||
LEAVE (" ");
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user