[banshee] [Shuffler] record selects in addition to discards



commit 2141f46a6a83ebc9e6a7514d5c6f2109c2eb61d0
Author: Gabriel Burt <gabriel burt gmail com>
Date:   Tue Mar 9 13:24:25 2010 -0800

    [Shuffler] record selects in addition to discards
    
    The Play Queue can record manually-added songs there, instead of as
    normal shuffles, so Mirage can weigh the manual selections higher.

 .../Banshee.Collection.Database/Shuffler.cs        |   32 ++++++++++---------
 .../Banshee.Database/BansheeDbFormatMigrator.cs    |   30 +++++++++++++++---
 .../Banshee.PlayQueue/PlayQueueSource.cs           |    8 +++--
 3 files changed, 47 insertions(+), 23 deletions(-)
---
diff --git a/src/Core/Banshee.Services/Banshee.Collection.Database/Shuffler.cs b/src/Core/Banshee.Services/Banshee.Collection.Database/Shuffler.cs
index ea88f48..1ed10bc 100644
--- a/src/Core/Banshee.Services/Banshee.Collection.Database/Shuffler.cs
+++ b/src/Core/Banshee.Services/Banshee.Collection.Database/Shuffler.cs
@@ -42,15 +42,20 @@ using Hyena.Collections;
 
 namespace Banshee.Collection.Database
 {
+    public enum ShuffleModificationType {
+        Discard = 0,
+        Insertion = 1
+    }
+
     public class Shuffler
     {
         public static readonly Shuffler Playback = new Shuffler () { Id = "playback", DbId = 0 };
 
         private static string shuffles_sql = "INSERT OR REPLACE INTO CoreShuffles (ShufflerID, LastShuffledAt, TrackID) ";
-        private static string discard_sql = "INSERT OR REPLACE INTO CoreShuffleDiscards (ShufflerID, LastDiscardedAt, TrackID) ";
+        private static string modify_sql   = "INSERT OR REPLACE INTO CoreShuffleModifications (ShufflerID, LastModifiedAt, ModificationType, TrackID) ";
 
         private static HyenaSqliteCommand add_shuffle_cmd = new HyenaSqliteCommand (String.Format ("{0} VALUES (?, ?, ?)", shuffles_sql));
-        private static HyenaSqliteCommand add_discard_cmd = new HyenaSqliteCommand (String.Format ("{0} VALUES (?, ?, ?)", discard_sql));
+        private static HyenaSqliteCommand add_discard_cmd = new HyenaSqliteCommand (String.Format ("{0} VALUES (?, ?, ?, ?)", modify_sql));
 
         private DateTime random_began_at = DateTime.MinValue;
         private DateTime last_random = DateTime.MinValue;
@@ -160,35 +165,32 @@ namespace Banshee.Collection.Database
             }
         }
 
-        public void RecordShuffle (DatabaseTrackInfo track)
+        internal void RecordShuffle (DatabaseTrackInfo track)
         {
             if (track != null) {
                 RecordShuffle (track.TrackId);
             }
         }
 
-        public void RecordShuffle (int trackId)
+        internal void RecordShuffle (int trackId)
         {
             ServiceManager.DbConnection.Execute (add_shuffle_cmd, this.DbId, DateTime.Now, trackId);
         }
 
-        public void RecordShuffles (DatabaseTrackListModel model, RangeCollection.Range range)
+        public void RecordShuffleModification (int trackId, ShuffleModificationType type)
         {
-            ServiceManager.DbConnection.Execute (String.Format ("{0} SELECT ?, ?, {1}", shuffles_sql, model.TrackIdsSql),
-                                                 DbId, DateTime.Now, model.CacheId, range.Start, range.Count);
+            ServiceManager.DbConnection.Execute (add_discard_cmd, this.DbId, DateTime.Now, (int)type, trackId);
         }
 
-        public void RecordDiscard (DatabaseTrackInfo track)
+        public void RecordInsertions (DatabaseTrackListModel model, RangeCollection.Range range)
         {
-            if (track != null) {
-                ServiceManager.DbConnection.Execute (add_discard_cmd, this.DbId, DateTime.Now, track.TrackId);
-            }
+            RecordShuffleModifications (model, range, ShuffleModificationType.Insertion);
         }
 
-        public void RecordDiscards (DatabaseTrackListModel model, RangeCollection.Range range)
+        public void RecordShuffleModifications (DatabaseTrackListModel model, RangeCollection.Range range, ShuffleModificationType type)
         {
-            ServiceManager.DbConnection.Execute (String.Format ("{0} SELECT ?, ?, {1}", discard_sql, model.TrackIdsSql),
-                                                 DbId, DateTime.Now, model.CacheId, range.Start, range.Count);
+            ServiceManager.DbConnection.Execute (String.Format ("{0} SELECT ?, ?, ?, {1}", modify_sql, model.TrackIdsSql),
+                                                 DbId, DateTime.Now, (int)type, model.CacheId, range.Start, range.Count);
         }
 
         private TrackInfo GetRandomTrack (string mode, bool repeat, bool resetSinceTime)
@@ -228,4 +230,4 @@ namespace Banshee.Collection.Database
             }
         }
     }
-}
+}
\ No newline at end of file
diff --git a/src/Core/Banshee.Services/Banshee.Database/BansheeDbFormatMigrator.cs b/src/Core/Banshee.Services/Banshee.Database/BansheeDbFormatMigrator.cs
index 37e9bf5..00d7d38 100644
--- a/src/Core/Banshee.Services/Banshee.Database/BansheeDbFormatMigrator.cs
+++ b/src/Core/Banshee.Services/Banshee.Database/BansheeDbFormatMigrator.cs
@@ -56,7 +56,7 @@ namespace Banshee.Database
         // NOTE: Whenever there is a change in ANY of the database schema,
         //       this version MUST be incremented and a migration method
         //       MUST be supplied to match the new version number
-        protected const int CURRENT_VERSION = 40;
+        protected const int CURRENT_VERSION = 41;
         protected const int CURRENT_METADATA_VERSION = 7;
 
 #region Migration Driver
@@ -905,6 +905,25 @@ namespace Banshee.Database
             return true;
         }
 
+        [DatabaseVersion (41)]
+        private bool Migrate_41 ()
+        {
+            Execute ("DROP TABLE IF EXISTS CoreShuffleDiscards");
+            Execute ("DROP INDEX IF EXISTS CoreShuffleDiscardsIndex");
+
+            Execute (@"
+                CREATE TABLE CoreShuffleModifications (
+                    ShufflerId           INTEGER,
+                    TrackID              INTEGER,
+                    LastModifiedAt       INTEGER,
+                    ModificationType     INTEGER,
+                    CONSTRAINT one_entry_per_track UNIQUE (ShufflerID, TrackID)
+                )
+            ");
+            Execute ("CREATE INDEX CoreShuffleModificationsIndex ON CoreShuffleModifications (ShufflerId, TrackID, LastModifiedAt, ModificationType)");
+            return true;
+        }
+
 
 #pragma warning restore 0169
 
@@ -1134,15 +1153,16 @@ namespace Banshee.Database
                 )
             ");
 
-            Execute(@"
-                CREATE TABLE CoreShuffleDiscards (
+            Execute (@"
+                CREATE TABLE CoreShuffleModifications (
                     ShufflerId           INTEGER,
                     TrackID              INTEGER,
-                    LastDiscardedAt      INTEGER,
+                    LastModifiedAt       INTEGER,
+                    ModificationType     INTEGER,
                     CONSTRAINT one_entry_per_track UNIQUE (ShufflerID, TrackID)
                 )
             ");
-            Execute("CREATE INDEX CoreShuffleDiscardsIndex ON CoreShuffleDiscards (ShufflerId, TrackID, LastDiscardedAt)");
+            Execute ("CREATE INDEX CoreShuffleModificationsIndex ON CoreShuffleModifications (ShufflerId, TrackID, LastModifiedAt, ModificationType)");
         }
 
 #endregion
diff --git a/src/Extensions/Banshee.PlayQueue/Banshee.PlayQueue/PlayQueueSource.cs b/src/Extensions/Banshee.PlayQueue/Banshee.PlayQueue/PlayQueueSource.cs
index 9a9a78b..7bd4bf8 100644
--- a/src/Extensions/Banshee.PlayQueue/Banshee.PlayQueue/PlayQueueSource.cs
+++ b/src/Extensions/Banshee.PlayQueue/Banshee.PlayQueue/PlayQueueSource.cs
@@ -237,7 +237,9 @@ namespace Banshee.PlayQueue
                 DbId, trackId, view_order, generated ? 1 : 0
             );
 
-            shuffler.RecordShuffle (trackId);
+            if (!generated) {
+                shuffler.RecordShuffleModification (trackId, ShuffleModificationType.Insertion);
+            }
 
             OnTracksAdded ();
             NotifyUser ();
@@ -292,7 +294,7 @@ namespace Banshee.PlayQueue
                     DbId, current_view_order
                 ));
 
-                WithTrackSelection (model, shuffler.RecordShuffles);
+                WithTrackSelection (model, shuffler.RecordInsertions);
 
                 // Add the tracks to the end of the queue.
                 WithTrackSelection (model, AddTrackRange);
@@ -442,7 +444,7 @@ namespace Banshee.PlayQueue
 
         protected override void RemoveTrackRange (DatabaseTrackListModel model, RangeCollection.Range range)
         {
-            shuffler.RecordDiscards (model, range);
+            shuffler.RecordShuffleModifications (model, range, ShuffleModificationType.Discard);
             base.RemoveTrackRange (model, range);
 
             model.Selection.UnselectRange (range.Start, range.End);



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