[Database] Remove orphaned objects. Added helpers to access releases and artists
This commit is contained in:
@@ -630,19 +630,15 @@ void
|
|||||||
Updater::checkAudioFiles( Stats& stats )
|
Updater::checkAudioFiles( Stats& stats )
|
||||||
{
|
{
|
||||||
|
|
||||||
LMS_LOG(MOD_DBUPDATER, SEV_DEBUG) << "Checking audio files...";
|
LMS_LOG(MOD_DBUPDATER, SEV_INFO) << "Checking audio files...";
|
||||||
Wt::Dbo::Transaction transaction(_db.getSession());
|
Wt::Dbo::Transaction transaction(_db.getSession());
|
||||||
|
|
||||||
std::vector<boost::filesystem::path> rootDirs = getRootDirectoriesByType(_db.getSession(), Database::MediaDirectory::Audio);
|
std::vector<boost::filesystem::path> rootDirs = getRootDirectoriesByType(_db.getSession(), Database::MediaDirectory::Audio);
|
||||||
|
|
||||||
LMS_LOG(MOD_DBUPDATER, SEV_DEBUG) << "Checking tracks...";
|
LMS_LOG(MOD_DBUPDATER, SEV_DEBUG) << "Checking tracks...";
|
||||||
typedef Wt::Dbo::collection< Wt::Dbo::ptr<Track> > Tracks;
|
auto tracks = Track::getAll(_db.getSession());
|
||||||
Tracks tracks = Track::getAll(_db.getSession());
|
for (auto track : tracks)
|
||||||
|
|
||||||
for (Tracks::iterator it = tracks.begin(); it != tracks.end(); ++it)
|
|
||||||
{
|
{
|
||||||
Track::pointer track = (*it);
|
|
||||||
|
|
||||||
if (!checkFile(track->getPath(), rootDirs, _audioExtensions))
|
if (!checkFile(track->getPath(), rootDirs, _audioExtensions))
|
||||||
{
|
{
|
||||||
track.remove();
|
track.remove();
|
||||||
@@ -651,20 +647,34 @@ Updater::checkAudioFiles( Stats& stats )
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Now process orphan Genre (no track)
|
// Now process orphan Genre (no track)
|
||||||
/* LMS_LOG(MOD_DBUPDATER, SEV_DEBUG) << "Checking Genres...";
|
LMS_LOG(MOD_DBUPDATER, SEV_DEBUG) << "Checking Genres...";
|
||||||
typedef Wt::Dbo::collection< Wt::Dbo::ptr<Genre> > Genres;
|
auto genres = Genre::getAll(_db.getSession());
|
||||||
Genres genres = Genre::getAll(_db.getSession());
|
for (auto genre : genres)
|
||||||
|
|
||||||
for (Genres::iterator it = genres.begin(); it != genres.end(); ++it)
|
|
||||||
{
|
{
|
||||||
Genre::pointer genre = (*it);
|
|
||||||
|
|
||||||
if (genre->getTracks().size() == 0)
|
if (genre->getTracks().size() == 0)
|
||||||
|
{
|
||||||
|
LMS_LOG(MOD_DBUPDATER, SEV_DEBUG) << "Removing orphan genre '" << genre->getName() << "'";
|
||||||
genre.remove();
|
genre.remove();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
||||||
LMS_LOG(MOD_DBUPDATER, SEV_DEBUG) << "Check audio files done!";
|
LMS_LOG(MOD_DBUPDATER, SEV_DEBUG) << "Checking artists...";
|
||||||
|
auto artists = Artist::getAllOrphans(_db.getSession());
|
||||||
|
for (auto artist : artists)
|
||||||
|
{
|
||||||
|
LMS_LOG(MOD_DBUPDATER, SEV_DEBUG) << "Removing orphan artist '" << artist->getName() << "'";
|
||||||
|
artist.remove();
|
||||||
|
}
|
||||||
|
|
||||||
|
LMS_LOG(MOD_DBUPDATER, SEV_DEBUG) << "Checking releases...";
|
||||||
|
auto releases = Release::getAllOrphans(_db.getSession());
|
||||||
|
for (auto release : releases)
|
||||||
|
{
|
||||||
|
LMS_LOG(MOD_DBUPDATER, SEV_DEBUG) << "Removing orphan release '" << release->getName() << "'";
|
||||||
|
release.remove();
|
||||||
|
}
|
||||||
|
|
||||||
|
LMS_LOG(MOD_DBUPDATER, SEV_INFO) << "Check audio files done!";
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|||||||
@@ -84,6 +84,18 @@ Artist::getByFilter(Wt::Dbo::Session& session, SearchFilter filter, int offset,
|
|||||||
return std::vector<pointer>(res.begin(), res.end());
|
return std::vector<pointer>(res.begin(), res.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::vector<Wt::Dbo::ptr<Release> >
|
||||||
|
Artist::getReleases()
|
||||||
|
{
|
||||||
|
assert(self());
|
||||||
|
assert(self()->id() != Wt::Dbo::dbo_traits<Artist>::invalidId() );
|
||||||
|
assert(session());
|
||||||
|
|
||||||
|
Wt::Dbo::collection< Wt::Dbo::ptr<Release> > res = session()->query<Wt::Dbo::ptr<Release> >("SELECT r FROM release r INNER JOIN artist a ON t.artist_id = a.id INNER JOIN track t ON t.release_id = r.id").where("a.id = ?").bind(id());
|
||||||
|
|
||||||
|
return std::vector< Wt::Dbo::ptr<Release> > (res.begin(), res.end());
|
||||||
|
}
|
||||||
|
|
||||||
Wt::Dbo::Query<Artist::pointer>
|
Wt::Dbo::Query<Artist::pointer>
|
||||||
Artist::getQuery(Wt::Dbo::Session& session, SearchFilter filter)
|
Artist::getQuery(Wt::Dbo::Session& session, SearchFilter filter)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -33,8 +33,9 @@ namespace Database
|
|||||||
|
|
||||||
class Track;
|
class Track;
|
||||||
class Genre;
|
class Genre;
|
||||||
|
class Release;
|
||||||
|
|
||||||
class Artist
|
class Artist : public Wt::Dbo::Dbo<Artist>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
@@ -58,6 +59,9 @@ class Artist
|
|||||||
std::string getName(void) const { return _name; }
|
std::string getName(void) const { return _name; }
|
||||||
std::string getMBID(void) const { return _MBID; }
|
std::string getMBID(void) const { return _MBID; }
|
||||||
|
|
||||||
|
// Get the releases that have at least one track for this artist
|
||||||
|
std::vector<Wt::Dbo::ptr<Release> > getReleases();
|
||||||
|
|
||||||
void setMBID(std::string mbid) { _MBID = mbid; }
|
void setMBID(std::string mbid) { _MBID = mbid; }
|
||||||
|
|
||||||
// Create
|
// Create
|
||||||
|
|||||||
@@ -71,7 +71,7 @@ Release::getAll(Wt::Dbo::Session& session, int offset, int size)
|
|||||||
std::vector<Release::pointer>
|
std::vector<Release::pointer>
|
||||||
Release::getAllOrphans(Wt::Dbo::Session& session)
|
Release::getAllOrphans(Wt::Dbo::Session& session)
|
||||||
{
|
{
|
||||||
Wt::Dbo::collection<Release::pointer> res = session.query< Wt::Dbo::ptr<Release> >("select a from artist a LEFT OUTER JOIN Track t ON a.id = t.artist_id WHERE t.id IS NULL");
|
Wt::Dbo::collection<Release::pointer> res = session.query< Wt::Dbo::ptr<Release> >("select r from release r LEFT OUTER JOIN Track t ON r.id = t.release_id WHERE t.id IS NULL");
|
||||||
|
|
||||||
return std::vector<pointer>(res.begin(), res.end());
|
return std::vector<pointer>(res.begin(), res.end());
|
||||||
}
|
}
|
||||||
@@ -129,4 +129,16 @@ Release::getByFilter(Wt::Dbo::Session& session, SearchFilter filter, int offset,
|
|||||||
return std::vector<pointer>(res.begin(), res.end());
|
return std::vector<pointer>(res.begin(), res.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::vector< Wt::Dbo::ptr<Artist> >
|
||||||
|
Release::getArtists()
|
||||||
|
{
|
||||||
|
assert(self());
|
||||||
|
assert(self()->id() != Wt::Dbo::dbo_traits<Release>::invalidId() );
|
||||||
|
assert(session());
|
||||||
|
|
||||||
|
Wt::Dbo::collection< Wt::Dbo::ptr<Artist> > res = session()->query<Wt::Dbo::ptr<Artist> >("SELECT a FROM artist a INNER JOIN release r ON r.id = t.release_id INNER JOIN track t ON t.release_id = r.id").where("r.id = ?").bind(id());
|
||||||
|
|
||||||
|
return std::vector< Wt::Dbo::ptr<Artist> > (res.begin(), res.end());
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace Database
|
} // namespace Database
|
||||||
|
|||||||
@@ -29,8 +29,9 @@ namespace Database
|
|||||||
{
|
{
|
||||||
|
|
||||||
class Track;
|
class Track;
|
||||||
|
class Release;
|
||||||
|
|
||||||
class Release
|
class Release : public Wt::Dbo::Dbo<Release>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
@@ -64,6 +65,8 @@ class Release
|
|||||||
std::string getMBID() const { return _MBID; }
|
std::string getMBID() const { return _MBID; }
|
||||||
bool isNone(void) const;
|
bool isNone(void) const;
|
||||||
boost::posix_time::time_duration getDuration(void) const;
|
boost::posix_time::time_duration getDuration(void) const;
|
||||||
|
std::vector<Wt::Dbo::ptr<Artist> > getArtists(); // Get the artists of this release
|
||||||
|
std::vector<Wt::Dbo::ptr<Track> > getTracks(); // Get the tracks of this release
|
||||||
|
|
||||||
void setMBID(std::string mbid) { _MBID = mbid; }
|
void setMBID(std::string mbid) { _MBID = mbid; }
|
||||||
|
|
||||||
|
|||||||
@@ -152,11 +152,10 @@ Genre::Genre(const std::string& name)
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<Genre::pointer>
|
Wt::Dbo::collection<Genre::pointer>
|
||||||
Genre::getAll(Wt::Dbo::Session& session, int offset, int size)
|
Genre::getAll(Wt::Dbo::Session& session)
|
||||||
{
|
{
|
||||||
Wt::Dbo::collection<pointer> res = session.find<Genre>().offset(offset).limit(size);
|
return session.find<Genre>();
|
||||||
return std::vector<Genre::pointer>(res.begin(), res.end());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Genre::pointer
|
Genre::pointer
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ class Genre
|
|||||||
static pointer getByName(Wt::Dbo::Session& session, const std::string& name);
|
static pointer getByName(Wt::Dbo::Session& session, const std::string& name);
|
||||||
static pointer getNone(Wt::Dbo::Session& session);
|
static pointer getNone(Wt::Dbo::Session& session);
|
||||||
static std::vector<pointer> getByFilter(Wt::Dbo::Session& session, SearchFilter filter, int offset = -1, int size = -1);
|
static std::vector<pointer> getByFilter(Wt::Dbo::Session& session, SearchFilter filter, int offset = -1, int size = -1);
|
||||||
static std::vector<pointer> getAll(Wt::Dbo::Session& session, int offset = -1, int size = -1);
|
static Wt::Dbo::collection<pointer> getAll(Wt::Dbo::Session& session);
|
||||||
|
|
||||||
// MVC models for the user interface
|
// MVC models for the user interface
|
||||||
// Genre ID, name, track count
|
// Genre ID, name, track count
|
||||||
|
|||||||
Reference in New Issue
Block a user