After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 656058 - Improve EBookBackendSqliteDB searching API
Improve EBookBackendSqliteDB searching API
Status: RESOLVED FIXED
Product: evolution-data-server
Classification: Platform
Component: Contacts
3.2.x (obsolete)
Other Linux
: Normal normal
: ---
Assigned To: evolution-addressbook-maintainers
Evolution QA team
Depends on:
Blocks:
 
 
Reported: 2011-08-05 21:48 UTC by Tristan Van Berkom
Modified: 2013-09-14 16:53 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Proposed patch for Sqlitedb (17.46 KB, patch)
2011-08-06 23:30 UTC, Tristan Van Berkom
committed Details | Review
Update to local addressbook backend for previous patch (5.15 KB, patch)
2011-08-06 23:32 UTC, Tristan Van Berkom
committed Details | Review

Description Tristan Van Berkom 2011-08-05 21:48:49 UTC
There are 2 problems with this api which I've spotted while using it
from the local (file) addressbook backend (for reference, these problems
presented themselves while working on bug 652172).

For clarity, assume that we are using an EBookBackendSqlitedb object
configured with 'store-vcards' FALSE (the sqlitedb is only used for
stashing quick access virtual 'summary' objects and possibly for listing 
contact uids).

  a.) When _sqlitedb_search() is called and the 'fields-of-interest'
      parameter is NULL, if the query is a valid summary query
      (i.e. it tests one of the summary fields) then shallow 'summary' 
      objects will be constructed and returned.

      This is either wrong or impractical for use from EBookBackendFile.

      The backend should construct virtual 'summary' vcards if and only if
      the 'fields-of-interest' is set to filter the vcard contents.

      For example, if you query for every vcard where the full name 
      contains the text 'jackson', you might be interested in more than
      only the summary fields.

  b.) This might be implicitly solved by tackling the first issue, but
      currently the _sqlitedb_search() api does not tell the caller if
      it actually performed a summary search or not.

      In the current situation the file backend will resort to iteration
      over the BDB even if the query was a valid summary query that returned
      zero results.


Before fixing this we should consider what is the right api, I think we
want the following features/type of integration:

  o If the query is an 'x-evolution-any-field' query, or a query for
    any of the summary fields, then sqlitedb_search() should perform a search.

    Otherwise it should resort to returning the 'stored-vcards' if any or
    NULL.

  o If fields-of-interest is specified, and all the fields of interest specified
    are part of the 'summary' fields, then virtual objects should be constructed
    and returned in the list.

  o If fields-of-interest is NULL or specifies fields that are not part of the
    summary, then the search (if possible) should still be performed.

    But in this case only a list of uids should be returned and not full 
    constructed virtual summary objects.

    In this specific case the backend will use the returned uids (as it did
    with the old EBookBackendSummary object) to pick up the full vcards from
    the BDB.

    Since the query will already be valid from the summary we can use
    e_data_book_notify_prefiltered_vcard() and avoid the extra processing but
    still provide full vcards for a NULL fields-of-interest (or a 
    fields-of-interest that is not covered by the summary).

Perhaps a fully usable api (from my current POV) would look like:

GSList *
e_book_backend_sqlitedb_search(EBookBackendSqliteDB *ebsdb,
			       const gchar *folderid,
			       const gchar *sexp,
			       /* const */ GHashTable *fields_of_interest,
                               gboolean    *searched_summary,
                               gboolean    *full_objects_returned,
			       GError     **error);

Essentially 'searched_summary' would let the caller know if the query
was actually used and performed on the sqlitedb (so the backend can
avoid further processing on a NULL result).

And 'full_objects_returned' would be set to TRUE if the full vcard was
returned (via store-vcards feature) and if all the fields-of-interest
were satisfied and a complete virtual vcard was constructed.

When 'full_objects_returned' is found to be FALSE, the backend can
rely on the returned list of contact UIDs to fetch complete vcards
from the BDB and notify with the 'prefiltered' api.


I am exceedingly sorry for my long and detailed bug reports and comments, I'm
obviously not comfortable enough with the code base to use the right buzzwords
and I'm trying to be extra clear to avoid any unneeded back and forth.
Comment 1 Tristan Van Berkom 2011-08-06 23:30:37 UTC
Created attachment 193364 [details] [review]
Proposed patch for Sqlitedb

This patch changes some apis to give more feedback to the caller
and let the caller leverage the sqlitedb object more efficiently.

It addresses all of the concerns I've brought up above.

Commit on openismus-work-master branch describes the patch well enough:

commit 13d0b48ec7d5a12aeb1f35ccdc141b5f384cf53b
Author: Tristan Van Berkom <tristan.van.berkom@gmail.com>
Date:   Sat Aug 6 19:22:55 2011 -0400

    Fixing sqlitedb object apis to be better usable from backends.
    
    This patch enhances the apis by adding 'gboolean *searched' and
    'gboolean *complete_vcards' parameters to a variety of the apis.
    
    This allows the backend to still use the sqlitedb to perform a
    quick search and fall back on loading the correct full vcards
    from another persistence (it also informs the caller if a search
    was indeed performed on the summary but had no matches, allowing
    the backends to avoid repeating the search in another persistence).
    
    Bug: https://bugzilla.gnome.org/show_bug.cgi?id=656058
Comment 2 Tristan Van Berkom 2011-08-06 23:32:23 UTC
Created attachment 193365 [details] [review]
Update to local addressbook backend for previous patch

This is part 2 of the same patch.

It updates the local file backend to leverage the new sqlitedb apis.

Commit on 'openismus-work-master' is:

commit f5aaa4fe82ec8051d1abc1fd617f112e92868e3d
Author: Tristan Van Berkom <tristan.van.berkom@gmail.com>
Date:   Sat Aug 6 19:25:50 2011 -0400

    Updated local addressbook backend for new sqlitedb apis.
    
    Now leverage the sqlitedb object better, save processing
    and return correct information according to the apis.
    
    Bug https://bugzilla.gnome.org/show_bug.cgi?id=656058.
Comment 3 Tristan Van Berkom 2011-08-06 23:35:26 UTC
Note that the changes to the local addressbook backend won't apply to
master without commit 97cf67329e6aee52335b06e6140c90f303b81d67 being
applied first.

The said commit was added at Ross Burton's request on bug 652178.

Would be nice to push that little commit upstream because it improves
the readability of following patches...
Comment 4 Milan Crha 2011-08-08 08:52:34 UTC
(In reply to comment #1)
> Created an attachment (id=193364) [details] [review]
> Proposed patch for Sqlitedb
> 
> This patch changes some apis to give more feedback to the caller
> and let the caller leverage the sqlitedb object more efficiently.
> 
> It addresses all of the concerns I've brought up above.

Well, breaking fix into two commits which are depending on the third is kinda bad, I expected that I'll apply the patch and eds will still work - the same may apply for each commit done to sources - but no, eds is broken with the SQLite cache patch.

Other things:

- in e_book_backend_sqlitedb_search_uids() is local_searched unused
- using 'complete_vcards' to indicate that the vCard is not complete, but
  artificial satisfying fields-of-interest is confusing to me, because under
  term 'complete_vcard' I would expect really complete vCard, the unfiltered.

So, I fixed what I could, with making those 'complete/complete_vcards' rather 'with_all_required_fields' variables, which is significantly longer, but I couldn't think of any better name.
Comment 5 Milan Crha 2011-08-08 08:52:53 UTC
Created commit edd2713 in eds master (3.1.5+)
Comment 6 André Klapper 2011-08-11 17:18:47 UTC
Tristan / Milan: I assume this commit triggered FTBFS bug 656277.
Can you please take a look at it?