Small update to Indexer to ensure playlist sort order is always

sequential with no holes.
This commit is contained in:
casey langen 2017-11-30 10:10:09 -08:00
parent 8bb70e7d98
commit 5fdffc292d
3 changed files with 40 additions and 3 deletions

View File

@ -695,6 +695,42 @@ void Indexer::SyncCleanup() {
}
}
/* make sure playlist sort orders are always sequential without holes. we
do this anyway, as playlists are updated, but there's no way to guarantee
it stays this way -- plugins, external processes, etc can cause problems */
{
db::Statement playlists("SELECT DISTINCT id FROM playlists", this->dbConnection);
while (playlists.Step() == db::Row) {
db::Statement tracks(
"SELECT track_external_id, sort_order "
"FROM playlist_tracks WHERE playlist_id=? "
"ORDER BY sort_order",
this->dbConnection);
int64_t playlistId = playlists.ColumnInt64(0);
tracks.BindInt64(0, playlistId);
db::Statement update(
"UPDATE playlist_tracks "
"SET sort_order=? "
"WHERE track_external_id=? AND sort_order=?",
this->dbConnection);
int order = 0;
while (tracks.Step() == db::Row) {
std::string externalId = tracks.ColumnText(0);
int sortOrder = tracks.ColumnInt32(1);
update.ResetAndUnbind();
update.BindInt32(0, order++);
update.BindText(1, externalId);
update.BindInt32(2, sortOrder);
update.Step();
}
}
}
/* optimize and shrink */
this->dbConnection.Execute("VACUUM");
}

View File

@ -103,13 +103,13 @@ namespace musik { namespace core {
};
typedef std::vector<std::shared_ptr<
musik::core::sdk::ITagReader> > TagReaderList;
musik::core::sdk::ITagReader>> TagReaderList;
typedef std::vector<std::shared_ptr<
musik::core::sdk::IDecoderFactory> > DecoderList;
musik::core::sdk::IDecoderFactory>> DecoderList;
typedef std::vector<std::shared_ptr<
musik::core::sdk::IIndexerSource> > IndexerSourceList;
musik::core::sdk::IIndexerSource>> IndexerSourceList;
void ThreadLoop();

View File

@ -117,6 +117,7 @@ namespace key {
static const std::string playlist_name = "playlist_name";
static const std::string subquery = "subquery";
static const std::string type = "type";
static const std::string sort_order = "sort_order";
static const std::string sort_orders = "sort_orders";
static const std::string predicate_category = "predicate_category";
static const std::string predicate_id = "predicate_id";