[PATCH] sort lots and entries on save

Andreas Köhler andi5.py at gmx.net
Mon Sep 15 15:14:59 EDT 2008


Hi Jim,

On Mon, 2008-09-15 at 11:35 -0700, Jim Radford wrote:
> The following patch sorts the lots and entries before saving them to
> the gnucash XML file.
> 
> This is an attempt to make saves more idempotent thereby facilitating
> the use of a revision control system on the gnucash XML files.
> 
> With this patch most of the needless and seemingly random churn is
> gone and I can add and remove a transation and expect there to be no
> changes to the gnucash file and I can add a transaction and expect
> that addition to be the only change in the file.
> 
> I'm curious to see if this patch affects save performance noticeably
> for anyone.  I don't have any large files to test with.

Two thoughts that come to my mind:

(1) qof_object_foreach_sorted() would not belong into
src/business/business-core but rather lib/libqof/qof.

(2) I do not like idea behind it.  You should not depend on the fact
that the save operation may be in any way idempotent.  At least that is
my opinion, others may speak differently.

Ciao,
-- andi5


> diff -u gnucash-2.2.4/src/backend/file/gnc-account-xml-v2.c gnucash-2.2.4-sorted/src/backend/file/gnc-account-xml-v2.c
> --- gnucash-2.2.4/src/backend/file/gnc-account-xml-v2.c	2008-03-02 05:24:27.000000000 -0800
> +++ gnucash-2.2.4-sorted/src/backend/file/gnc-account-xml-v2.c	2008-04-23 15:06:13.000000000 -0700
> @@ -139,6 +139,8 @@
>      {
>         xmlNodePtr toaddto = xmlNewChild(ret, NULL, BAD_CAST act_lots_string, NULL);
>  
> +       lots = g_list_sort(lots, qof_instance_guid_compare);
> +
>         for (n = lots; n; n=n->next)
>         {
>            GNCLot * lot = n->data;
> --- gnucash-2.2.5/src/business/business-core/file/gnc-entry-xml-v2.c	2008-01-07 17:05:59.000000000 -0800
> +++ gnucash-2.2.5/src/business/business-core/file/gnc-entry-xml-v2.c~	2008-07-01 17:41:19.000000000 -0700
> @@ -814,9 +814,27 @@
>  }
>  
> +static void
> +do_append (QofInstance *qof_p, gpointer list_p)
> +{
> +  GList **list = list_p;
> +  *list = g_list_append(*list, qof_p);
> +}
> +
> +static void
> +qof_object_foreach_sorted (QofIdTypeConst type_name, QofBook *book, QofInstanceForeachCB cb, gpointer user_data)
> +{
> +  GList *list = NULL, *n, *l;
> +  qof_object_foreach(type_name, book, do_append, &list);
> +  list = g_list_sort(list, qof_instance_guid_compare);
> +  for (l = list; l; l = l->next)
> +    cb(l->data, user_data);
> +  g_list_free(list);
> +}
> +
>  static void
>  entry_write (FILE *out, QofBook *book)
>  {
> -  qof_object_foreach (_GNC_MOD_NAME, book, xml_add_entry, (gpointer) out);
> +  qof_object_foreach_sorted (_GNC_MOD_NAME, book, xml_add_entry, (gpointer) out);
>  }
>  
>  static void

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 197 bytes
Desc: This is a digitally signed message part
Url : http://lists.gnucash.org/pipermail/gnucash-devel/attachments/20080915/4139b203/attachment.bin 


More information about the gnucash-devel mailing list