diff --git a/data/data.qrc b/data/data.qrc
index 998e3b743..7c6e0ec0c 100644
--- a/data/data.qrc
+++ b/data/data.qrc
@@ -71,5 +71,6 @@
media-playlist-repeat-off.png
media-playlist-shuffle-off.png
schema-4.sql
+ schema-5.sql
diff --git a/data/schema-5.sql b/data/schema-5.sql
new file mode 100644
index 000000000..ae71cf6e7
--- /dev/null
+++ b/data/schema-5.sql
@@ -0,0 +1,8 @@
+ALTER TABLE songs ADD COLUMN effective_compilation NOT NULL DEFAULT 0;
+
+UPDATE songs SET effective_compilation = ((compilation OR sampler OR forced_compilation_on) AND NOT forced_compilation_off) + 0;
+
+CREATE INDEX idx_comp_artist ON songs (effective_compilation, artist);
+
+UPDATE schema_version SET version=5;
+
diff --git a/src/librarybackend.cpp b/src/librarybackend.cpp
index ab2b4ba26..9ff1fc973 100644
--- a/src/librarybackend.cpp
+++ b/src/librarybackend.cpp
@@ -16,7 +16,7 @@
const char* LibraryBackend::kDatabaseName = "clementine.db";
-const int LibraryBackend::kSchemaVersion = 4;
+const int LibraryBackend::kSchemaVersion = 5;
void (*LibraryBackend::_sqlite3_create_function) (
sqlite3*, const char*, int, int, void*,
@@ -535,7 +535,10 @@ void LibraryBackend::UpdateCompilations() {
}
// Now mark the songs that we think are in compilations
- QSqlQuery update("UPDATE songs SET sampler = :sampler WHERE album = :album", db);
+ QSqlQuery update("UPDATE songs"
+ " SET sampler = :sampler,"
+ " effective_compilation = ((compilation OR :sampler OR forced_compilation_on) AND NOT forced_compilation_off) + 0"
+ " WHERE album = :album", db);
QSqlQuery find_songs("SELECT ROWID, " + QString(Song::kColumnSpec) + " FROM songs"
" WHERE album = :album AND sampler = :sampler", db);
@@ -629,6 +632,7 @@ LibraryBackend::AlbumList LibraryBackend::GetAlbums(const QString& artist,
last_album = info.album_name;
last_artist = info.artist;
}
+
return ret;
}
diff --git a/src/libraryquery.cpp b/src/libraryquery.cpp
index 402ebbf66..3fd53b548 100644
--- a/src/libraryquery.cpp
+++ b/src/libraryquery.cpp
@@ -41,12 +41,7 @@ void LibraryQuery::AddWhere(const QString& column, const QVariant& value) {
}
void LibraryQuery::AddCompilationRequirement(bool compilation) {
- if (compilation)
- where_clauses_ << "((compilation = 1 OR sampler = 1 OR forced_compilation_on = 1)"
- " AND forced_compilation_off = 0)";
- else
- where_clauses_ << "((compilation = 0 AND sampler = 0 AND forced_compilation_on = 0)"
- " OR forced_compilation_off = 1)";
+ where_clauses_ << QString("effective_compilation = %1").arg(compilation ? 1 : 0);
}
QSqlQuery LibraryQuery::Query(QSqlDatabase db) const {
diff --git a/src/song.cpp b/src/song.cpp
index ae0e50389..b63bd02c4 100644
--- a/src/song.cpp
+++ b/src/song.cpp
@@ -40,7 +40,7 @@ const char* Song::kColumnSpec =
"length, bitrate, samplerate, directory, filename, "
"mtime, ctime, filesize, sampler, art_automatic, art_manual, "
"filetype, playcount, lastplayed, rating, forced_compilation_on, "
- "forced_compilation_off";
+ "forced_compilation_off, effective_compilation";
const char* Song::kBindSpec =
":title, :album, :artist, :albumartist, :composer, "
@@ -48,7 +48,7 @@ const char* Song::kBindSpec =
":length, :bitrate, :samplerate, :directory_id, :filename, "
":mtime, :ctime, :filesize, :sampler, :art_automatic, :art_manual, "
":filetype, :playcount, :lastplayed, :rating, :forced_compilation_on, "
- ":forced_compilation_off";
+ ":forced_compilation_off, :effective_compilation";
const char* Song::kUpdateSpec =
"title = :title, album = :album, artist = :artist, "
@@ -61,7 +61,8 @@ const char* Song::kUpdateSpec =
"art_automatic = :art_automatic, art_manual = :art_manual, "
"filetype = :filetype, playcount = :playcount, lastplayed = :lastplayed, "
"rating = :rating, forced_compilation_on = :forced_compilation_on, "
- "forced_compilation_off = :forced_compilation_off";
+ "forced_compilation_off = :forced_compilation_off, "
+ "effective_compilation = :effective_compilation";
TagLibFileRefFactory Song::kDefaultFactory;
@@ -302,6 +303,8 @@ void Song::InitFromQuery(const QSqlQuery& q) {
d->forced_compilation_on_ = q.value(28).toBool();
d->forced_compilation_off_ = q.value(29).toBool();
+ // effective_compilation = 30
+
#undef tostr
#undef toint
#undef tofloat
@@ -373,6 +376,8 @@ void Song::BindToQuery(QSqlQuery *query) const {
query->bindValue(":forced_compilation_on", d->forced_compilation_on_ ? 1 : 0);
query->bindValue(":forced_compilation_off", d->forced_compilation_off_ ? 1 : 0);
+ query->bindValue(":effective_compilation", is_compilation() ? 1 : 0);
+
#undef intval
}