Disabling group cache updating during reindexing. Handled by event handler now.
[qwerkisync] / DBBackends / RtcomEventLogger.cpp
index 20daa23..c34a8df 100644 (file)
@@ -399,7 +399,7 @@ void RtcomEventLogger::Reindex()
                                                        if(min == 0)
                                                                min = one;
 
-                                                       qDebug() << "( " << one << ", " << two << " )";
+                                                       //qDebug() << "( " << one << ", " << two << " )";
                                                        mapping.insert(one, two);
                                                }
                                        }
@@ -437,23 +437,23 @@ void RtcomEventLogger::Reindex()
                        int val(min);
                        sequence.append(0);
                        sequence.append(val);
-                       qDebug().nospace() << "val1: " << val << ", ";
+                       //qDebug().nospace() << "val1: " << val << ", ";
 
                        while((val = mapping[val]) && val != min)
                        {
                                sequence.append(val);
-                               qDebug().nospace() << val << ", ";
+                               //qDebug().nospace() << val << ", ";
                        }
                        sequence.append(0);
 
-                       qDebug().nospace() << "seq: ";
+                       //qDebug().nospace() << "seq: ";
                        QList<QPair<int,int> > updates;
                        int last(sequence.first());
                        foreach(int seq, sequence)
                        {
                                if(seq != last)
                                {
-                                       qDebug().nospace() << seq << ", " << last << ", ";
+                                       //qDebug().nospace() << seq << ", " << last << ", ";
                                        updates.append(QPair<int,int>(seq, last));
                                }
 
@@ -488,7 +488,7 @@ void RtcomEventLogger::Reindex()
                                }
                        }
 
-                       qDebug() << query;
+                       //qDebug() << query;
 
                        QSqlQuery * UpdateQuery(new QSqlQuery( db ));
                        if(UpdateQuery != NULL)
@@ -502,9 +502,7 @@ void RtcomEventLogger::Reindex()
                                        {
                                                for( QStringList::const_iterator currentStatement(statements.constBegin()); currentStatement != statements.constEnd(); ++currentStatement)
                                                {
-                                                       if ( UpdateQuery->exec( *currentStatement ))
-                                                               qDebug() << "Query OK, " << UpdateQuery->numRowsAffected() << " rows affected.";
-                                                       else
+                                                       if (!UpdateQuery->exec(*currentStatement))
                                                        {
                                                                qDebug() << "Query Failed: " << *currentStatement;
                                                                throw std::exception();
@@ -525,98 +523,6 @@ void RtcomEventLogger::Reindex()
                        }
                }while(changesRequired > 0);
 
-               // Update the group cache so the last events are correct
-               {
-                       qDebug() << "Updating most recent events.";
-
-                       // Grab group UIDs from group cache
-                       QSqlQuery * dbq(new QSqlQuery( db ));
-                       dbq->setForwardOnly( true );
-
-                       const char * groupUIDListSQL("SELECT group_uid FROM GroupCache");
-                       if (dbq->exec(groupUIDListSQL))
-                       {
-                               qDebug() << "Query OK, " << dbq->numRowsAffected() << " rows affected.";
-                               qDebug() << "GroupUIDs:";
-
-                               QSet<QString> groupUIDs;
-                               while( dbq->next() )
-                               {
-                                       QString groupUID(dbq->value(0).value<QString>());
-
-                                       qDebug() << groupUID;
-                                       groupUIDs.insert(groupUID);
-                               }
-
-                               // Iterate over group UIDS
-                               if(groupUIDs.count() > 0)
-                               {
-                                       // Build a batch statement to update every group with
-                                       // the most recent event
-
-                                       // Ignore 'data' failures (i.e. no events but present in the
-                                       // cache)- something else's been monkeying with the DB, and
-                                       // we can't account for everything.
-                                       const QString updateGroupCacheWithLatestEventsSQL(
-                                               "UPDATE OR IGNORE GroupCache SET event_id = "
-                                                       "(SELECT id FROM events WHERE group_uid = \"%1\" "
-                                                       " ORDER BY id DESC LIMIT 1)"
-                                               " WHERE group_uid = \"%1\";");
-                                       QString updateGroupCacheWithLatestEventsBatchSQL;
-                                       foreach(QString groupUID, groupUIDs)
-                                       {
-                                               updateGroupCacheWithLatestEventsBatchSQL.append(
-                                                       updateGroupCacheWithLatestEventsSQL
-                                                       .arg(groupUID)
-                                                       ).append("\n");
-                                       }
-
-                                       // Execute the statement in single-statement chunks thanks
-                                       // to QT's inability to call the SQLite function supporting
-                                       // multiple statements
-
-                                       QSqlQuery * setLatestEventInGroupCacheSQL(new QSqlQuery( db ));
-                                       if(NULL != setLatestEventInGroupCacheSQL)
-                                       {
-                                               setLatestEventInGroupCacheSQL->setForwardOnly( true );
-
-                                               if(db.transaction())
-                                               {
-                                                       QStringList statements = updateGroupCacheWithLatestEventsBatchSQL.trimmed().split(";", QString::SkipEmptyParts);
-                                                       try
-                                                       {
-                                                               for( QStringList::const_iterator currentStatement(statements.constBegin()); currentStatement != statements.constEnd(); ++currentStatement)
-                                                               {
-                                                                       if ( setLatestEventInGroupCacheSQL->exec( *currentStatement ))
-                                                                               qDebug() << "Query OK, " << setLatestEventInGroupCacheSQL->numRowsAffected() << " rows affected.";
-                                                                       else
-                                                                       {
-                                                                               qDebug() << "Query Failed: " << *currentStatement;
-                                                                               throw std::exception();
-                                                                       }
-                                                               }
-
-                                                               qDebug() << "Committing.";
-                                                               db.commit();
-                                                       }
-                                                       catch(...)
-                                                       {
-                                                               qDebug() << "Rolling back.";
-                                                               db.rollback();
-                                                       }
-                                               }
-                                               else
-                                                       qDebug() << "Unable to start transaction.";
-                                       }
-                               }
-                       }
-                       else
-                       {
-                               qDebug() << "SQL EXEC Error: "<< "EXEC query failed";
-                               qDebug() << "Query: " << groupUIDListSQL;
-                       }
-               }
-
                qDebug() << "Closing.";
                db.close();
                QSqlDatabase::removeDatabase( "QSQLITE" );
@@ -632,10 +538,10 @@ QDebug operator<<(QDebug dbg, RTComElEvent &event)
        dbg.nospace() << "\tservice:\t" << event.fld_service << "\n";
        dbg.nospace() << "\tevt_typ_id:\t" << event.fld_event_type_id << "\n";
        dbg.nospace() << "\tevt_typ:\t" << event.fld_event_type << "\n";
-       dbg.nospace() << "\tstore-time:\t" << QDateTime::fromTime_t(event.fld_storage_time) << "\n";
-       dbg.nospace() << "\tstart-time:\t" << QDateTime::fromTime_t(event.fld_start_time) << "\n";
-       dbg.nospace() << "\tend-time:\t\t" << QDateTime::fromTime_t(event.fld_end_time) << "\n";
-       dbg.nospace() << "\tis-read:\t\t" << (event.fld_is_read ? "true" : "false") << "\n";
+       dbg.nospace() << "\tstore-time:\t" << QDateTime::fromTime_t(event.fld_storage_time).toUTC() << "\n";
+       dbg.nospace() << "\tstart-time:\t" << QDateTime::fromTime_t(event.fld_start_time).toUTC() << "\n";
+       dbg.nospace() << "\tend-time:\t" << QDateTime::fromTime_t(event.fld_end_time).toUTC() << "\n";
+       dbg.nospace() << "\tis-read:\t" << (event.fld_is_read ? "true" : "false") << "\n";
        dbg.nospace() << "\tdirection:\t" << (event.fld_outgoing ? "Outgoing" : "Incoming") << "\n";
        dbg.nospace() << "\tflags:\t\t" << "0x" << QString::number(event.fld_flags, 16) << "\n";
        dbg.nospace() << "\tbytes sent:\t" << event.fld_bytes_sent << "\n";
@@ -644,6 +550,7 @@ QDebug operator<<(QDebug dbg, RTComElEvent &event)
        dbg.nospace() << "\tlocal-name:\t" << event.fld_local_name << "\n";
        dbg.nospace() << "\tremote-uid:\t" << event.fld_remote_uid << "\n";
        dbg.nospace() << "\tremote-name:\t" << event.fld_remote_name << "\n";
+       dbg.nospace() << "\tremote-ebid:\t" << event.fld_remote_ebook_uid << "\n";
        dbg.nospace() << "\tchannel:\t\t" << event.fld_channel << "\n";
        dbg.nospace() << "\tfree-text:\t" << event.fld_free_text << "\n";
        dbg.nospace() << "\tgroup-uid:\t" << event.fld_group_uid << "\n";