4.10.3-2: add gtktreeviewmodel fixes
[arch-packages.git] / banshee / trunk / sqlite_fix.patch
blob7dfa53817293c1453f36332b19afd6187cbfbac1
1 From 700ad9b1686d0b46073b7b2e6cea8e01e30d5f52 Mon Sep 17 00:00:00 2001
2 From: Samuel Gyger <gygersamuel@gmail.com>
3 Date: Fri, 12 Dec 2014 17:07:45 +0100
4 Subject: Database: fix performance for the new SQLite's query planner
5 (bgo#740879)
7 Starting with sqlite version 3.8.6, a new query planner is used.
8 To get back the performance on filling the CoreCache Table,
9 this commit provides hints to sqlite (using the UNLIKELY statement).
10 But the UNLIKELY statement is only supported in version 3.8.1 and
11 above, so in order not to raise the version of the dependency on
12 sqlite, we can use this new clause conditionally.
14 diff --git a/src/Core/Banshee.Services/Banshee.Collection.Database/DatabaseAlbumArtistListModel.cs b/src/Core/Banshee.Services/Banshee.Collection.Database/DatabaseAlbumArtistListModel.cs
15 index dee9c81..e91018b 100644
16 --- a/src/Core/Banshee.Services/Banshee.Collection.Database/DatabaseAlbumArtistListModel.cs
17 +++ b/src/Core/Banshee.Services/Banshee.Collection.Database/DatabaseAlbumArtistListModel.cs
18 @@ -46,7 +46,7 @@ namespace Banshee.Collection.Database
19 ReloadFragmentFormat = @"
20 FROM CoreArtists WHERE CoreArtists.ArtistID IN
21 (SELECT CoreAlbums.ArtistID FROM CoreAlbums, CoreTracks, CoreCache{0}
22 - WHERE CoreCache.ModelID = {1} AND
23 + WHERE {4}(CoreCache.ModelID = {1}) AND
24 CoreTracks.AlbumID = CoreAlbums.AlbumID AND
25 EXISTS (SELECT 1 FROM CoreArtists WHERE ArtistID = CoreAlbums.ArtistID) AND
26 CoreCache.ItemID = {2} {3})
27 diff --git a/src/Core/Banshee.Services/Banshee.Collection.Database/DatabaseAlbumListModel.cs b/src/Core/Banshee.Services/Banshee.Collection.Database/DatabaseAlbumListModel.cs
28 index 0705eab..213f137 100644
29 --- a/src/Core/Banshee.Services/Banshee.Collection.Database/DatabaseAlbumListModel.cs
30 +++ b/src/Core/Banshee.Services/Banshee.Collection.Database/DatabaseAlbumListModel.cs
31 @@ -56,7 +56,7 @@ namespace Banshee.Collection.Database
32 ReloadFragmentFormat = @"
33 FROM CoreAlbums WHERE CoreAlbums.AlbumID IN
34 (SELECT CoreTracks.AlbumID FROM CoreTracks, CoreCache{0}
35 - WHERE CoreCache.ModelID = {1} AND
36 + WHERE {4}(CoreCache.ModelID = {1}) AND
37 CoreCache.ItemId = {2} {3})
38 ORDER BY CoreAlbums.TitleSortKey, CoreAlbums.ArtistNameSortKey";
40 diff --git a/src/Core/Banshee.Services/Banshee.Collection.Database/DatabaseArtistListModel.cs b/src/Core/Banshee.Services/Banshee.Collection.Database/DatabaseArtistListModel.cs
41 index f7a2b4b..171e9e2 100644
42 --- a/src/Core/Banshee.Services/Banshee.Collection.Database/DatabaseArtistListModel.cs
43 +++ b/src/Core/Banshee.Services/Banshee.Collection.Database/DatabaseArtistListModel.cs
44 @@ -49,7 +49,7 @@ namespace Banshee.Collection.Database
45 ReloadFragmentFormat = @"
46 FROM CoreArtists WHERE CoreArtists.ArtistID IN
47 (SELECT CoreTracks.ArtistID FROM CoreTracks, CoreCache{0}
48 - WHERE CoreCache.ModelID = {1} AND
49 + WHERE {4}(CoreCache.ModelID = {1}) AND
50 CoreCache.ItemID = {2} {3})
51 ORDER BY NameSortKey";
53 diff --git a/src/Core/Banshee.Services/Banshee.Collection.Database/DatabaseFilterListModel.cs b/src/Core/Banshee.Services/Banshee.Collection.Database/DatabaseFilterListModel.cs
54 index 018a0f4..2a5d4fd 100644
55 --- a/src/Core/Banshee.Services/Banshee.Collection.Database/DatabaseFilterListModel.cs
56 +++ b/src/Core/Banshee.Services/Banshee.Collection.Database/DatabaseFilterListModel.cs
57 @@ -57,10 +57,10 @@ namespace Banshee.Collection.Database
60 protected readonly U select_all_item;
61 - private HyenaSqliteConnection connection;
62 + private BansheeDbConnection connection;
64 public DatabaseFilterListModel (string name, string label, Banshee.Sources.DatabaseSource source,
65 - DatabaseTrackListModel trackModel, HyenaSqliteConnection connection, SqliteModelProvider<T> provider, U selectAllItem, string uuid)
66 + DatabaseTrackListModel trackModel, BansheeDbConnection connection, SqliteModelProvider<T> provider, U selectAllItem, string uuid)
67 : base (trackModel)
69 this.source = source;
70 @@ -124,7 +124,8 @@ namespace Banshee.Collection.Database
71 "{0}.{1} AND CoreTracks.TrackID = {0}.{2}",
72 FilteredModel.JoinTable, FilteredModel.JoinPrimaryKey, FilteredModel.JoinColumn)
73 : "CoreTracks.TrackID",
74 - filtered ? GetFilterFragment () : ""
75 + filtered ? GetFilterFragment () : "",
76 + connection.LikelihoodSupport ? "UNLIKELY" : ""
80 diff --git a/src/Core/Banshee.Services/Banshee.Collection.Database/DatabaseQueryFilterModel.cs b/src/Core/Banshee.Services/Banshee.Collection.Database/DatabaseQueryFilterModel.cs
81 index a4c00fb..339e351 100644
82 --- a/src/Core/Banshee.Services/Banshee.Collection.Database/DatabaseQueryFilterModel.cs
83 +++ b/src/Core/Banshee.Services/Banshee.Collection.Database/DatabaseQueryFilterModel.cs
84 @@ -37,6 +37,7 @@ using Hyena.Data.Sqlite;
85 using Mono.Unix;
87 using Banshee.ServiceStack;
88 +using Banshee.Database;
90 namespace Banshee.Collection.Database
92 @@ -51,7 +52,7 @@ namespace Banshee.Collection.Database
93 private string select_all_fmt;
95 public DatabaseQueryFilterModel (Banshee.Sources.DatabaseSource source, DatabaseTrackListModel trackModel,
96 - HyenaSqliteConnection connection, string select_all_fmt, string uuid, QueryField field, string filter_column)
97 + BansheeDbConnection connection, string select_all_fmt, string uuid, QueryField field, string filter_column)
98 : base (field.Name, field.Label, source, trackModel, connection, QueryFilterInfo<T>.CreateProvider (filter_column, field), new QueryFilterInfo<T> (), String.Format ("{0}-{1}", uuid, field.Name))
100 this.field = field;
101 @@ -59,7 +60,7 @@ namespace Banshee.Collection.Database
103 ReloadFragmentFormat = @"
104 FROM CoreTracks, CoreCache{0}
105 - WHERE CoreCache.ModelID = {1} AND CoreCache.ItemID = {2} {3}
106 + WHERE {4}(CoreCache.ModelID = {1}) AND CoreCache.ItemID = {2} {3}
107 ORDER BY Value";
109 QueryFields = new QueryFieldSet (query_filter_field);
110 diff --git a/src/Core/Banshee.Services/Banshee.Collection.Database/DatabaseYearListModel.cs b/src/Core/Banshee.Services/Banshee.Collection.Database/DatabaseYearListModel.cs
111 index b58d1df..5f96d2f 100644
112 --- a/src/Core/Banshee.Services/Banshee.Collection.Database/DatabaseYearListModel.cs
113 +++ b/src/Core/Banshee.Services/Banshee.Collection.Database/DatabaseYearListModel.cs
114 @@ -47,7 +47,7 @@ namespace Banshee.Collection.Database
115 FROM (SELECT MIN(CoreTracks.TrackID) AS TrackID, CoreTracks.Year FROM CoreTracks GROUP BY CoreTracks.Year) AS CoreTracks
116 WHERE CoreTracks.Year IN
117 (SELECT CoreTracks.Year FROM CoreTracks, CoreCache{0}
118 - WHERE CoreCache.ModelID = {1} AND
119 + WHERE {4}(CoreCache.ModelID = {1}) AND
120 CoreCache.ItemID = {2} {3})
121 ORDER BY Year";
123 diff --git a/src/Core/Banshee.Services/Banshee.Database/BansheeDbConnection.cs b/src/Core/Banshee.Services/Banshee.Database/BansheeDbConnection.cs
124 index e9bbbf5..3ae0728 100644
125 --- a/src/Core/Banshee.Services/Banshee.Database/BansheeDbConnection.cs
126 +++ b/src/Core/Banshee.Services/Banshee.Database/BansheeDbConnection.cs
127 @@ -52,6 +52,20 @@ namespace Banshee.Database
128 get { return configuration; }
131 + private bool? likelihood_support = null;
132 + public bool LikelihoodSupport {
133 + get {
134 + if (!likelihood_support.HasValue) {
135 + // emulate the SQLITE_VERSION_NUMBER macro
136 + string[] v = Query<string> ("SELECT sqlite_version ()").Split ('.');
137 + likelihood_support = (Int32.Parse (v[0]) * 1000000 +
138 + Int32.Parse (v[1]) * 1000 +
139 + Int32.Parse (v[2])) >= 3008001;
141 + return likelihood_support.Value;
145 public BansheeDbConnection () : this (DatabaseFile)