banshee r4370 - in trunk/banshee: . src/Core/Banshee.Services/Banshee.Collection.Database src/Core/Banshee.Services/Banshee.Database src/Libraries/Hyena/Hyena src/Libraries/Hyena/Hyena/Tests
- From: gburt svn gnome org
- To: svn-commits-list gnome org
- Subject: banshee r4370 - in trunk/banshee: . src/Core/Banshee.Services/Banshee.Collection.Database src/Core/Banshee.Services/Banshee.Database src/Libraries/Hyena/Hyena src/Libraries/Hyena/Hyena/Tests
- Date: Thu, 14 Aug 2008 20:55:45 +0000 (UTC)
Author: gburt
Date: Thu Aug 14 20:55:45 2008
New Revision: 4370
URL: http://svn.gnome.org/viewvc/banshee?rev=4370&view=rev
Log:
2008-08-14 Gabriel Burt <gabriel burt gmail com>
* src/Core/Banshee.Services/Banshee.Collection.Database/DatabaseTrackInfo.cs:
Add protected MetadataHash property, really only used to store a hashed
string of title, artist, album, genre, duration, etc. Will be used for
sql-powered sync - select all the MetadataHashes that are in the library
but not the device, and vice-versa.
* src/Core/Banshee.Services/Banshee.Database/BansheeDbFormatMigrator.cs:
Add MetadataHash column to CoreTracks, and trigger metadata refresh so the
hashes are generated for existing tracks.
* src/Libraries/Hyena/Hyena/CryptoUtil.cs: Speed up the MD5 hashing by
caching the MD5 algorithm object, and speed up the IsMd5Encoded method by
caching the Regex.
* src/Libraries/Hyena/Hyena/Tests/CryptoUtilTests.cs: Make public instead
of internal so these tests are actually ran, and add tests for null/empty
strings.
Modified:
trunk/banshee/ChangeLog
trunk/banshee/src/Core/Banshee.Services/Banshee.Collection.Database/DatabaseTrackInfo.cs
trunk/banshee/src/Core/Banshee.Services/Banshee.Database/BansheeDbFormatMigrator.cs
trunk/banshee/src/Libraries/Hyena/Hyena/CryptoUtil.cs
trunk/banshee/src/Libraries/Hyena/Hyena/Tests/CryptoUtilTests.cs
Modified: trunk/banshee/src/Core/Banshee.Services/Banshee.Collection.Database/DatabaseTrackInfo.cs
==============================================================================
--- trunk/banshee/src/Core/Banshee.Services/Banshee.Collection.Database/DatabaseTrackInfo.cs (original)
+++ trunk/banshee/src/Core/Banshee.Services/Banshee.Collection.Database/DatabaseTrackInfo.cs Thu Aug 14 20:55:45 2008
@@ -360,6 +360,21 @@
protected string TitleLowered {
get { return TrackTitle == null ? null : TrackTitle.ToLower (); }
}
+
+ [DatabaseColumn(Select = false)]
+ protected string MetadataHash {
+ get {
+ System.Text.StringBuilder sb = new System.Text.StringBuilder ();
+ sb.Append (AlbumTitle);
+ sb.Append (ArtistName);
+ sb.Append ((int)Duration.TotalSeconds);
+ sb.Append (Genre);
+ sb.Append (TrackTitle);
+ sb.Append (TrackNumber);
+ sb.Append (Year);
+ return Hyena.CryptoUtil.Md5Encode (sb.ToString (), System.Text.Encoding.UTF8);
+ }
+ }
[DatabaseColumn]
public override int TrackNumber {
Modified: trunk/banshee/src/Core/Banshee.Services/Banshee.Database/BansheeDbFormatMigrator.cs
==============================================================================
--- trunk/banshee/src/Core/Banshee.Services/Banshee.Database/BansheeDbFormatMigrator.cs (original)
+++ trunk/banshee/src/Core/Banshee.Services/Banshee.Database/BansheeDbFormatMigrator.cs Thu Aug 14 20:55:45 2008
@@ -52,8 +52,8 @@
// 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 = 17;
- protected const int CURRENT_METADATA_VERSION = 2;
+ protected const int CURRENT_VERSION = 18;
+ protected const int CURRENT_METADATA_VERSION = 3;
#region Migration Driver
@@ -482,6 +482,17 @@
#endregion
+#region Version 18
+
+ [DatabaseVersion (18)]
+ private bool Migrate_18 ()
+ {
+ Execute ("ALTER TABLE CoreTracks ADD COLUMN MetadataHash TEXT");
+ return true;
+ }
+
+#endregion
+
#pragma warning restore 0169
#region Fresh database setup
@@ -559,7 +570,8 @@
LastPlayedStamp INTEGER,
LastSkippedStamp INTEGER,
DateAddedStamp INTEGER,
- DateUpdatedStamp INTEGER
+ DateUpdatedStamp INTEGER,
+ MetadataHash TEXT
)
", (int)TrackMediaAttributes.Default, (int)StreamPlaybackError.None));
Execute("CREATE INDEX CoreTracksPrimarySourceIndex ON CoreTracks(ArtistID, AlbumID, PrimarySourceID, Disc, TrackNumber, Uri)");
@@ -729,7 +741,8 @@
LastPlayedStamp,
NULL,
DateAddedStamp,
- DateAddedStamp
+ DateAddedStamp,
+ NULL
FROM Tracks
", (int)TrackMediaAttributes.Default, (int)StreamPlaybackError.None));
Modified: trunk/banshee/src/Libraries/Hyena/Hyena/CryptoUtil.cs
==============================================================================
--- trunk/banshee/src/Libraries/Hyena/Hyena/CryptoUtil.cs (original)
+++ trunk/banshee/src/Libraries/Hyena/Hyena/CryptoUtil.cs Thu Aug 14 20:55:45 2008
@@ -35,10 +35,13 @@
{
public static class CryptoUtil
{
+ // A-Z is ignored on purpose
+ private static Regex md5_regex = new Regex ("^[a-f0-9]{32}$", RegexOptions.Compiled);
+ private static MD5 md5 = MD5.Create ();
+
public static bool IsMd5Encoded (string text)
{
- // A-Z is ignored on purpose
- return text.Length != 32 ? false : Regex.IsMatch (text, "^[a-f0-9]{32}$");
+ return text == null || text.Length != 32 ? false : md5_regex.IsMatch (text);
}
public static string Md5Encode (string text)
@@ -51,8 +54,7 @@
if (String.IsNullOrEmpty (text)) {
return String.Empty;
}
-
- MD5 md5 = MD5.Create ();
+
byte [] hash = md5.ComputeHash (encoding.GetBytes (text));
StringBuilder shash = new StringBuilder ();
Modified: trunk/banshee/src/Libraries/Hyena/Hyena/Tests/CryptoUtilTests.cs
==============================================================================
--- trunk/banshee/src/Libraries/Hyena/Hyena/Tests/CryptoUtilTests.cs (original)
+++ trunk/banshee/src/Libraries/Hyena/Hyena/Tests/CryptoUtilTests.cs Thu Aug 14 20:55:45 2008
@@ -35,12 +35,14 @@
namespace Hyena.Tests
{
[TestFixture]
- internal class CryptoUtilTests
+ public class CryptoUtilTests
{
[Test]
public void Md5Encode ()
{
Assert.AreEqual ("ae2b1fca515949e5d54fb22b8ed95575", CryptoUtil.Md5Encode ("testing"));
+ Assert.AreEqual ("", CryptoUtil.Md5Encode (null));
+ Assert.AreEqual ("", CryptoUtil.Md5Encode (""));
}
[Test]
@@ -50,7 +52,20 @@
Assert.IsFalse (CryptoUtil.IsMd5Encoded ("abc233"));
Assert.IsFalse (CryptoUtil.IsMd5Encoded ("lebowski"));
Assert.IsFalse (CryptoUtil.IsMd5Encoded ("ae2b1fca515949e5g54fb22b8ed95575"));
+ Assert.IsFalse (CryptoUtil.IsMd5Encoded (null));
+ Assert.IsFalse (CryptoUtil.IsMd5Encoded (""));
}
+
+ /*[Test]
+ public void Md5Performance ()
+ {
+ int max = 10000;
+ using (new Timer (String.Format ("Computed {0} MD5 hashes", max))) {
+ for (int i = 0; i < max; i++) {
+ CryptoUtil.Md5Encode ("LkaJSd Flkjdf234234lkj3WlkejewrVlkdf @343434 dsfjk 3497u34 l 2008 lkjdf");
+ }
+ }
+ }*/
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]