mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
Bug 797945 - Imap bayes conversion runs many times
When the Imap Editor is loaded, the bayes KVP entries are tested to see if they are required to be converted to flat entries. This involves a function that scans every account and if it finds entries that need changing, the change is made and book property GNC_FEATURE_GUID_FLAT_BAYESIAN is added so further scans are not made. As the Imap Editor loops over the account list also, if there are no bayes KVP changes then the conversion function gets called for every account in the list. This can also happen to a lesser degree when doing imports. To stop this a flag is set once the convert to flat function has been run so it only runs once and only lasts for the session.
This commit is contained in:
parent
0e9f368b4a
commit
416e234232
@ -1140,6 +1140,10 @@ gnc_file_open_file (GtkWindow *parent, const char * newfile, gboolean open_reado
|
||||
if (!gnc_file_query_save (parent, TRUE))
|
||||
return FALSE;
|
||||
|
||||
/* Reset the flag that indicates the conversion of the bayes KVP
|
||||
* entries has been run */
|
||||
gnc_account_reset_convert_bayes_to_flat ();
|
||||
|
||||
return gnc_post_file_open (parent, newfile, open_readonly);
|
||||
}
|
||||
|
||||
|
@ -449,6 +449,10 @@ gnc_main_window_cmd_file_open (GtkAction *action, GncMainWindowActionData *data)
|
||||
if (!gnc_main_window_all_finish_pending())
|
||||
return;
|
||||
|
||||
/* Reset the flag that indicates the conversion of the bayes KVP
|
||||
* entries has been run */
|
||||
gnc_account_reset_convert_bayes_to_flat ();
|
||||
|
||||
gnc_window_set_progressbar_window (GNC_WINDOW(data->window));
|
||||
#ifdef HAVE_DBI_DBI_H
|
||||
gnc_ui_file_access_for_open (GTK_WINDOW (data->window));
|
||||
|
@ -55,6 +55,9 @@ static QofLogModule log_module = GNC_MOD_ACCOUNT;
|
||||
/* The Canonical Account Separator. Pre-Initialized. */
|
||||
static gchar account_separator[8] = ".";
|
||||
static gunichar account_uc_separator = ':';
|
||||
|
||||
static bool imap_convert_bayes_to_flat_run = false;
|
||||
|
||||
/* Predefined KVP paths */
|
||||
static const std::string KEY_ASSOC_INCOME_ACCOUNT("ofx/associated-income-account");
|
||||
static const std::string KEY_RECONCILE_INFO("reconcile-info");
|
||||
@ -5602,6 +5605,12 @@ imap_convert_bayes_to_flat (QofBook * book)
|
||||
return ret;
|
||||
}
|
||||
|
||||
void
|
||||
gnc_account_reset_convert_bayes_to_flat (void)
|
||||
{
|
||||
imap_convert_bayes_to_flat_run = false;
|
||||
}
|
||||
|
||||
/*
|
||||
* Here we check to see the state of import map data.
|
||||
*
|
||||
@ -5616,10 +5625,13 @@ imap_convert_bayes_to_flat (QofBook * book)
|
||||
static void
|
||||
check_import_map_data (QofBook *book)
|
||||
{
|
||||
if (gnc_features_check_used (book, GNC_FEATURE_GUID_FLAT_BAYESIAN))
|
||||
if (gnc_features_check_used (book, GNC_FEATURE_GUID_FLAT_BAYESIAN) ||
|
||||
imap_convert_bayes_to_flat_run)
|
||||
return;
|
||||
|
||||
/* This function will set GNC_FEATURE_GUID_FLAT_BAYESIAN if necessary.*/
|
||||
imap_convert_bayes_to_flat (book);
|
||||
imap_convert_bayes_to_flat_run = true;
|
||||
}
|
||||
|
||||
static constexpr double threshold = .90 * probability_factor; /* 90% */
|
||||
|
@ -1504,6 +1504,11 @@ void gnc_account_delete_map_entry (Account *acc, char *head, char *category,
|
||||
*/
|
||||
void gnc_account_delete_all_bayes_maps (Account *acc);
|
||||
|
||||
/** Reset the flag that indicates the function imap_convert_bayes_to_flat
|
||||
* has been run
|
||||
*/
|
||||
void gnc_account_reset_convert_bayes_to_flat (void);
|
||||
|
||||
/** @} */
|
||||
|
||||
|
||||
|
@ -345,6 +345,8 @@ TEST_F(ImapBayesTest, ConvertBayesData)
|
||||
root->set_path({IMAP_FRAME_BAYES, sausage, "Expense#Drink"}, val3);
|
||||
root->set_path({IMAP_FRAME_BAYES, foo, "Expense#Food"}, new KvpValue{*val2});
|
||||
root->set_path({IMAP_FRAME_BAYES, salt, acct1_guid}, new KvpValue{*val1});
|
||||
/* make sure to reset the conversion has been run flag */
|
||||
gnc_account_reset_convert_bayes_to_flat ();
|
||||
/*Calling into the imap functions should trigger a conversion.*/
|
||||
gnc_account_imap_add_account_bayes(t_imap, t_list5, t_expense_account2); //pork and sausage; account Food
|
||||
// convert from 'Asset-Bank' to 'Asset-Bank' guid
|
||||
|
Loading…
Reference in New Issue
Block a user