[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    =?utf-8?q?=5Bamarok=5D_src/core-impl/collections/db/sql=3A_Bette?=
From:       Ralf Engels <ralf-engels () gmx ! de>
Date:       2011-02-26 23:57:27
Message-ID: 20110226235727.2041DA60B4 () git ! kde ! org
[Download RAW message or body]

Git commit c1cd386a92f8c234ae83dec712d8839204f10e46 by Ralf Engels.
Committed on 26/02/2011 at 21:43.
Pushed by rengels into branch 'master'.

Better handling of deleted tracks.
We need to ensure that the urls table entries of tracks don't block new tracks.
Also I added a check for duplicate tracks (no idea where I got them from)

Auto tests still run flawless

M  +7    -2    src/core-impl/collections/db/sql/SqlRegistry.cpp     
M  +8    -1    src/core-impl/collections/db/sql/SqlScanResultProcessor.cpp     
M  +1    -1    src/core-impl/collections/db/sql/SqlScanResultProcessor.h     

http://commits.kde.org/amarok/c1cd386a92f8c234ae83dec712d8839204f10e46

diff --git a/src/core-impl/collections/db/sql/SqlRegistry.cpp \
b/src/core-impl/collections/db/sql/SqlRegistry.cpp index 4d27a97..8ba264b 100644
--- a/src/core-impl/collections/db/sql/SqlRegistry.cpp
+++ b/src/core-impl/collections/db/sql/SqlRegistry.cpp
@@ -265,7 +265,7 @@ SqlRegistry::updateCachedUid( const QString &oldUid, const \
QString &newUid )  // TODO: improve uid handling
     if( m_uidMap.contains( newUid ) )
         warning() << "updating uid to an already existing uid.";
-    else if( !m_uidMap.contains( oldUid ) )
+    else if( !oldUid.isEmpty() && !m_uidMap.contains( oldUid ) )
         warning() << "updating uid from a non existing uid.";
     else
     {
@@ -317,7 +317,12 @@ SqlRegistry::removeTrack( int urlId, const QString uid )
     QString query = QString( "DELETE FROM tracks where url=%1;" ).arg( urlId );
     m_collection->sqlStorage()->query( query );
     // keep the urls and statistics entry in case a deleted track is restored later.
-    query = QString( "UPDATE urls SET deviceid=0, rpath='', directory=NULL WHERE \
id=%1;").arg( urlId ); +    // however we need to change rpath so that it does not \
block new tracks +    // (deviceid,rpath is a unique key)
+    // so we just write the uid into the path
+    query = QString( "UPDATE urls SET deviceid=0, rpath='%1', directory=NULL "
+                     "WHERE id=%2;").arg( m_collection->sqlStorage()->escape(uid),
+                                          urlId );
     m_collection->sqlStorage()->query( query );
     query = QString( "UPDATE statistics SET deleted=1 WHERE url=%1;").arg( urlId );
     m_collection->sqlStorage()->query( query );
diff --git a/src/core-impl/collections/db/sql/SqlScanResultProcessor.cpp \
b/src/core-impl/collections/db/sql/SqlScanResultProcessor.cpp index 9476790..31bfca8 \
                100644
--- a/src/core-impl/collections/db/sql/SqlScanResultProcessor.cpp
+++ b/src/core-impl/collections/db/sql/SqlScanResultProcessor.cpp
@@ -407,11 +407,18 @@ SqlScanResultProcessor::cacheUrlsInit()
 }
 
 void
-SqlScanResultProcessor::cacheUrlsInsert( const UrlEntry &entry )
+SqlScanResultProcessor::cacheUrlsInsert( UrlEntry entry )
 {
     if( !m_urlsCache.contains( entry.id ) )
         cacheUrlsRemove( entry.id );
 
+    if( !entry.path.isEmpty() && m_urlsCachePath.contains( entry.path ) ) {
+        // no idea how this can happen, but we clean it up
+        debug() << "Duplicate path in database:"<<entry.path;
+        removeTrack( entry.id, entry.uid ); // this will not delete the statistics
+        entry.path.clear();
+    }
+
     m_urlsCache.insert( entry.id, entry );
     m_urlsCacheUid.insert( entry.uid, entry.id );
     m_urlsCachePath.insert( entry.path, entry.id );
diff --git a/src/core-impl/collections/db/sql/SqlScanResultProcessor.h \
b/src/core-impl/collections/db/sql/SqlScanResultProcessor.h index dc465ab..1bd96db \
                100644
--- a/src/core-impl/collections/db/sql/SqlScanResultProcessor.h
+++ b/src/core-impl/collections/db/sql/SqlScanResultProcessor.h
@@ -99,7 +99,7 @@ class AMAROK_SQLCOLLECTION_EXPORT_TESTS SqlScanResultProcessor : \
public ScanResu  };
 
         void cacheUrlsInit();
-        void cacheUrlsInsert( const UrlEntry &entry );
+        void cacheUrlsInsert( UrlEntry entry );
         void cacheUrlsRemove( int id );
 
         QHash<int, UrlEntry> m_urlsCache;


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic