is it possible to "refine" an existing QofQuery multiple times?

Christian Stimming stimming at tuhh.de
Sun Aug 6 06:54:59 EDT 2006


Just a question about the qofquery.h interface: Is it possible to refine a 
query multiple times? 

In the generic importer, for each imported transaction a query is performed 
where the criteria are 1. to match the known import-account, and 2. to match 
a certain date interval. It turned out that each query will internally 
iterate over all splits in the book, not only all splits in the 
import-account, which takes a long long time. Derek told me it's not very 
likely that this would change in soon. So I would like to split this query 
into two parts: First make one query to get all splits belonging to the known 
import-account and store this query (or its result) for the rest of the 
imported transactions. Then, for each additional imported transaction, run 
the query matching on the certain date interval, but run the query only on 
the result of the first query. If this were possible, then I'd get rid of a 
huge performance bottleneck in the generic importer. Here's how I'd imagine 
this to work (in gnc_import_find_split_matches() in import-backend.c):

    Query *stored_query = ...; // from somewhere
    Account *importaccount =  ...; // from somewhere
    time_t download_time = ...; // from somewhere
    Query *query;

    if (stored_query && stored_query_account &&
	stored_query_account == importaccount)
      {
	/* Stored query already exists */
      }
    else
      {
	/* First run the query only to restrict the set on the account */
        stored_query = xaccMallocQuery();
	xaccQuerySetBook (stored_query, gnc_get_current_book());
	xaccQueryAddSingleAccountMatch (stored query, importaccount,			    
					QOF_QUERY_AND);
	stored_query_account = importaccount;
        qof_query_run(stored_query); // or something else here???
      }

    /* Now refine the stored query.  */
    query = qof_query_copy(stored_query); 
    // ^^^^ will this avoid iterating over all splits????
    xaccQueryAddDateMatchTT (query,
			     TRUE, download_time - match_date_hardlimit*86400,
			     TRUE, download_time + match_date_hardlimit*86400,
			     QOF_QUERY_AND);
    /* Execute final (second) query. */
    list_element = xaccQueryGetSplits (query);

Any hints? Thanks a lot.

Christian


More information about the gnucash-devel mailing list