Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Bump music DB to v71: Store when library last updated in versiontagsc…
…an table
  • Loading branch information
DaveTBlake committed Jun 2, 2018
1 parent f149361 commit 8e926db
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
29 changes: 27 additions & 2 deletions xbmc/music/MusicDatabase.cpp
Expand Up @@ -201,7 +201,7 @@ void CMusicDatabase::CreateTables()
m_pDS->exec("CREATE TABLE art(art_id INTEGER PRIMARY KEY, media_id INTEGER, media_type TEXT, type TEXT, url TEXT)");

CLog::Log(LOGINFO, "create versiontagscan table");
m_pDS->exec("CREATE TABLE versiontagscan (idVersion integer, iNeedsScan integer)");
m_pDS->exec("CREATE TABLE versiontagscan (idVersion INTEGER, iNeedsScan INTEGER, lastscanned VARCHAR(20))");
m_pDS->exec(PrepareSQL("INSERT INTO versiontagscan (idVersion, iNeedsScan) values(%i, 0)", GetSchemaVersion()));
}

Expand Down Expand Up @@ -381,6 +381,7 @@ void CMusicDatabase::CreateViews()
bool CMusicDatabase::AddAlbum(CAlbum& album)
{
BeginTransaction();
SetLibraryLastUpdated();

album.idAlbum = AddAlbum(album.strAlbum,
album.strMusicBrainzAlbumID,
Expand Down Expand Up @@ -453,6 +454,7 @@ bool CMusicDatabase::AddAlbum(CAlbum& album)
bool CMusicDatabase::UpdateAlbum(CAlbum& album)
{
BeginTransaction();
SetLibraryLastUpdated();

UpdateAlbum(album.idAlbum,
album.strAlbum, album.strMusicBrainzAlbumID,
Expand Down Expand Up @@ -1074,6 +1076,8 @@ int CMusicDatabase::AddGenre(std::string& strGenre)

bool CMusicDatabase::UpdateArtist(const CArtist& artist)
{
SetLibraryLastUpdated();

UpdateArtist(artist.idArtist,
artist.strArtist, artist.strSortName,
artist.strMusicBrainzArtistID, artist.bScrapedMBID,
Expand Down Expand Up @@ -3283,6 +3287,7 @@ bool CMusicDatabase::CleanupOrphanedItems()
// paths aren't cleaned up here - they're cleaned up in RemoveSongsFromPath()
if (NULL == m_pDB.get()) return false;
if (NULL == m_pDS.get()) return false;
SetLibraryLastUpdated();
if (!CleanupAlbums()) return false;
if (!CleanupArtists()) return false;
if (!CleanupGenres()) return false;
Expand Down Expand Up @@ -5330,6 +5335,13 @@ void CMusicDatabase::UpdateTables(int version)
// Update all songs iStartOffset and iEndOffset to milliseconds instead of frames (* 1000 / 75)
m_pDS->exec("UPDATE song SET iStartOffset = iStartOffset * 40 / 3, iEndOffset = iEndOffset * 40 / 3 \n");
}
if (version < 71)
{
// Add lastscanned to versiontagscan table
m_pDS->exec("ALTER TABLE versiontagscan ADD lastscanned VARCHAR(20)\n");
CDateTime dateAdded = CDateTime::GetCurrentDateTime();
m_pDS->exec(PrepareSQL("UPDATE versiontagscan SET lastscanned = '%s'", dateAdded.GetAsDBDateTime().c_str()));
}

// Set the verion of tag scanning required.
// Not every schema change requires the tags to be rescanned, set to the highest schema version
Expand All @@ -5350,7 +5362,7 @@ void CMusicDatabase::UpdateTables(int version)

int CMusicDatabase::GetSchemaVersion() const
{
return 70;
return 71;
}

int CMusicDatabase::GetMusicNeedsTagScan()
Expand Down Expand Up @@ -5397,6 +5409,18 @@ void CMusicDatabase::SetMusicTagScanVersion(int version /* = 0 */)
m_pDS->exec(PrepareSQL("UPDATE versiontagscan SET idVersion=%i", version));
}

std::string CMusicDatabase::GetLibraryLastUpdated()
{
return GetSingleValue("SELECT lastscanned FROM versiontagscan LIMIT 1");
}

void CMusicDatabase::SetLibraryLastUpdated()
{
CDateTime dateUpdated = CDateTime::GetCurrentDateTime();
m_pDS->exec(PrepareSQL("UPDATE versiontagscan SET lastscanned = '%s'", dateUpdated.GetAsDBDateTime().c_str()));
}


unsigned int CMusicDatabase::GetSongIDs(const Filter &filter, std::vector<std::pair<int,int> > &songIDs)
{
try
Expand Down Expand Up @@ -6231,6 +6255,7 @@ bool CMusicDatabase::RemoveSongsFromPath(const std::string &path1, MAPSONGS& son
// Note: when used to remove all songs from a path and its subpath (exact=false), this
// does miss archived songs.
std::string path(path1);
SetLibraryLastUpdated();
try
{
if (!URIUtils::HasSlashAtEnd(path))
Expand Down
3 changes: 3 additions & 0 deletions xbmc/music/MusicDatabase.h
Expand Up @@ -585,6 +585,9 @@ class CMusicDatabase : public CDatabase
*/
void SetMusicTagScanVersion(int version = 0);

std::string GetLibraryLastUpdated();
void SetLibraryLastUpdated();

protected:
std::map<std::string, int> m_genreCache;
std::map<std::string, int> m_pathCache;
Expand Down

0 comments on commit 8e926db

Please sign in to comment.