[banshee] PrimarySource: Fix pruning of artists from the database (bgo#677288)



commit 68fb08cedec1213ab8b3a629184ef3940864b1f9
Author: Bertrand Lorentz <bertrand lorentz gmail com>
Date:   Sun Jun 3 15:43:04 2012 +0200

    PrimarySource: Fix pruning of artists from the database (bgo#677288)
    
    The existing query to prune artists from the CoreArtists table was
    only keeping artists referenced in CoreTracks, thus removing all album
    artists that were not also track artists.
    
    Fix this query to also keep artists referenced in CoreAlbums. Also
    refactor the query to use NOT EXISTS (...) instead of NOT IN (...),
    which is much faster with big databases.
    
    In addition, prune the CoreAlbums table first, so that deleted album
    artists will be pruned from CoreArtists by the second query.
    
    For some reason, for the CoreAlbums table, the NOT EXISTS (...) query
    has slightly worse performance, so we keep the NOT IN (...) query.
    Apparently, query optimization is more of an art than a science...

 .../Banshee.Sources/PrimarySource.cs               |    6 ++++--
 1 files changed, 4 insertions(+), 2 deletions(-)
---
diff --git a/src/Core/Banshee.Services/Banshee.Sources/PrimarySource.cs b/src/Core/Banshee.Services/Banshee.Sources/PrimarySource.cs
index 2a6dc39..9c2f310 100644
--- a/src/Core/Banshee.Services/Banshee.Sources/PrimarySource.cs
+++ b/src/Core/Banshee.Services/Banshee.Sources/PrimarySource.cs
@@ -104,8 +104,10 @@ namespace Banshee.Sources
         ", BansheeQuery.UriField.Column));
 
         protected HyenaSqliteCommand prune_artists_albums_command = new HyenaSqliteCommand (@"
-            DELETE FROM CoreArtists WHERE ArtistID NOT IN (SELECT ArtistID FROM CoreTracks);
-            DELETE FROM CoreAlbums WHERE AlbumID NOT IN (SELECT AlbumID FROM CoreTracks)
+            DELETE FROM CoreAlbums WHERE AlbumID NOT IN (SELECT AlbumID FROM CoreTracks);
+            DELETE FROM CoreArtists WHERE
+                    NOT EXISTS (SELECT 1 FROM CoreTracks WHERE CoreTracks.ArtistID = CoreArtists.ArtistID)
+                AND NOT EXISTS (SELECT 1 FROM CoreAlbums WHERE CoreAlbums.ArtistID = CoreArtists.ArtistID)
         ");
 
         protected HyenaSqliteCommand purge_tracks_command = new HyenaSqliteCommand (@"



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