Test allowing oggs through the scanner. Clean up some transactions on first launch to prevent locking from a uncapped while loop. Also don't start the event loop without 3 tracks or voting can't happen.

This commit is contained in:
Kevin Whitaker
2017-02-06 00:44:31 -05:00
parent dc37ef9e06
commit 166443f9ad

View File

@@ -140,13 +140,25 @@ void GroovePlayerMgr::grooveEventLoop()
sqlSession.mapClass<User>("user"); sqlSession.mapClass<User>("user");
sqlSession.mapClass<AudioTrack>("tracks"); sqlSession.mapClass<AudioTrack>("tracks");
sqlSession.mapClass<UserAction>("actions"); sqlSession.mapClass<UserAction>("actions");
Wt::Dbo::Transaction transaction(sqlSession);
//Wait until at least one track is in DB. Wt::Dbo::Transaction transaction(sqlSession);
if(sqlSession.query<int>("select count(fingerprint) from tracks") < 1) int trackCount = sqlSession.query<int>("select count(fingerprint) from tracks");
transaction.commit();
//Wait until at least 3 tracks are in DB to prevent nothing to vote on.
if(trackCount < 3)
{ {
while(sqlSession.query<int>("select count(fingerprint) from tracks") < 1){} while(trackCount < 3)
{
Wt::Dbo::Transaction transaction(sqlSession);
trackCount = sqlSession.query<int>("select count(fingerprint) from tracks");
transaction.commit();
std::this_thread::sleep_for(std::chrono::milliseconds(500));
}
} }
Wt::Dbo::Transaction bootTransaction(sqlSession);
//Pick initial track to bootstrap. //Pick initial track to bootstrap.
int tracksPlayedBefore = sqlSession.query<int>("select count(fingerprint) from tracks as t join actions on (actions.action = 3 or actions.action = 2) and actions.track_id = t.id"); int tracksPlayedBefore = sqlSession.query<int>("select count(fingerprint) from tracks as t join actions on (actions.action = 3 or actions.action = 2) and actions.track_id = t.id");
@@ -160,7 +172,8 @@ void GroovePlayerMgr::grooveEventLoop()
int trackCount = sqlSession.query<int>("select count(fingerprint) from tracks"); int trackCount = sqlSession.query<int>("select count(fingerprint) from tracks");
selectedTrack = *sqlSession.find<AudioTrack>().limit(1).offset(rand() % trackCount).resultValue(); selectedTrack = *sqlSession.find<AudioTrack>().limit(1).offset(rand() % trackCount).resultValue();
} }
transaction.commit(); bootTransaction.commit();
struct GroovePlaylist* playlist = groove_playlist_create(); struct GroovePlaylist* playlist = groove_playlist_create();
currentPlaylist = playlist; currentPlaylist = playlist;
struct GroovePlayer* player = groove_player_create(); struct GroovePlayer* player = groove_player_create();
@@ -477,7 +490,7 @@ void GroovePlayerMgr::grooveAudioScannerLoop()
{ {
extensionLowered.push_back(std::tolower(elem)); extensionLowered.push_back(std::tolower(elem));
} }
if(extensionLowered == ".mp3") //TODO:think about supporting more than mp3s. if(extensionLowered == ".mp3" || extensionLowered == ".ogg") //TODO:think about supporting more than mp3s and oggs.
{ {
if(addFileToTrackDBIfTagged(&sqlSession, p.path())) if(addFileToTrackDBIfTagged(&sqlSession, p.path()))
{ {