[tracker/wip/carlosg/update-perf: 27/61] libtracker-sparql/core: Loosen TrackerDBStatement ownership restrictions




commit da42069780903ddf0f3c06fd3fb133344e7ea397
Author: Carlos Garnacho <carlosg gnome org>
Date:   Sun Jul 31 12:49:56 2022 +0200

    libtracker-sparql/core: Loosen TrackerDBStatement ownership restrictions
    
    Currently, we enforce that every TrackerDBStatement is either executed,
    reset, or fully iterated before considering the statement ready for use
    elsewhere again. We enforce this even with TrackerDBStatements that are
    requested not to be cached.
    
    Since we have a number of relatively invariable internal queries and
    updates (e.g. resource refcount maintenance), it could be benefitial for
    those to have the update machinery able to keep TrackerDBStatements
    around, instead of building query strings just to be able to get a
    statement from the DB interface.
    
    In order to allow for this usecase, soften the restrictions about a
    TrackerDBStatement being only able to be executed once for uncached
    statements (i.e. TRACKER_DB_STATEMENT_CACHE_TYPE_NONE). Callers will
    be able to keep them around for multiple executions.
    
    Since the variable name carrying this accounting had a slightly
    misleading name (the cache owns the statements, just borrows them for
    execution), also change the name so it is more intuitively correct.

 src/libtracker-sparql/core/tracker-db-interface-sqlite.c | 14 +++++---------
 1 file changed, 5 insertions(+), 9 deletions(-)
---
diff --git a/src/libtracker-sparql/core/tracker-db-interface-sqlite.c 
b/src/libtracker-sparql/core/tracker-db-interface-sqlite.c
index af8c834ca..ffb333c8a 100644
--- a/src/libtracker-sparql/core/tracker-db-interface-sqlite.c
+++ b/src/libtracker-sparql/core/tracker-db-interface-sqlite.c
@@ -125,7 +125,7 @@ struct TrackerDBStatement {
        TrackerDBInterface *db_interface;
        sqlite3_stmt *stmt;
        guint stmt_is_used : 1;
-       guint stmt_is_owned : 1;
+       guint stmt_is_borrowed : 1;
        TrackerDBStatement *next;
        TrackerDBStatement *prev;
 };
@@ -2618,7 +2618,7 @@ tracker_db_interface_lru_lookup (TrackerDBInterface          *db_interface,
 
        /* a) Cached */
 
-       if (stmt && stmt->stmt_is_owned) {
+       if (stmt && stmt->stmt_is_borrowed) {
                /* c) Forced non-cached
                 * prepared statement is owned somewhere else, create new uncached one
                 */
@@ -2777,7 +2777,7 @@ tracker_db_interface_create_statement (TrackerDBInterface           *db_interfac
                                                 stmt);
        }
 
-       stmt->stmt_is_owned = TRUE;
+       stmt->stmt_is_borrowed = cache_type != TRACKER_DB_STATEMENT_CACHE_TYPE_NONE;
 
        tracker_db_interface_unlock (db_interface);
 
@@ -3021,7 +3021,6 @@ static TrackerDBStatement *
 tracker_db_statement_sqlite_grab (TrackerDBStatement *stmt)
 {
        g_assert (!stmt->stmt_is_used);
-       g_assert (stmt->stmt_is_owned);
        stmt->stmt_is_used = TRUE;
        g_object_ref (stmt->db_interface);
        return g_object_ref (stmt);
@@ -3032,13 +3031,12 @@ tracker_db_statement_sqlite_release (TrackerDBStatement *stmt)
 {
        TrackerDBInterface *iface = stmt->db_interface;
 
-       g_assert (stmt->stmt_is_owned);
+       stmt->stmt_is_borrowed = FALSE;
 
-       stmt->stmt_is_owned = FALSE;
+       tracker_db_statement_sqlite_reset (stmt);
 
        if (stmt->stmt_is_used) {
                stmt->stmt_is_used = FALSE;
-               tracker_db_statement_sqlite_reset (stmt);
                g_object_unref (stmt);
                g_object_unref (iface);
        }
@@ -3820,8 +3818,6 @@ tracker_db_cursor_init (TrackerDBCursor *cursor)
 static void
 tracker_db_statement_sqlite_reset (TrackerDBStatement *stmt)
 {
-       g_assert (!stmt->stmt_is_used);
-
        sqlite3_reset (stmt->stmt);
        sqlite3_clear_bindings (stmt->stmt);
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]