Remove orphaned cluster types

This commit is contained in:
emeric
2018-03-04 15:34:33 +01:00
parent 2db46260ab
commit c0c5273e92
3 changed files with 19 additions and 0 deletions
+9
View File
@@ -271,6 +271,15 @@ ClusterType::ClusterType(std::string name)
{
}
std::vector<ClusterType::pointer>
ClusterType::getAllOrphans(Wt::Dbo::Session& session)
{
Wt::Dbo::collection<pointer> res = session.query<Wt::Dbo::ptr<ClusterType>>("select c_t from cluster_type c_t LEFT OUTER JOIN cluster c ON c_t.id = c.cluster_type_id WHERE c.id IS NULL");
return std::vector<pointer>(res.begin(), res.end());
}
ClusterType::pointer
ClusterType::getByName(Wt::Dbo::Session& session, std::string name)
{
+1
View File
@@ -96,6 +96,7 @@ class ClusterType : public Wt::Dbo::Dbo<ClusterType>
ClusterType() {}
ClusterType(std::string name);
static std::vector<pointer> getAllOrphans(Wt::Dbo::Session& session);
static pointer getByName(Wt::Dbo::Session& session, std::string name);
static std::vector<pointer> getAll(Wt::Dbo::Session& session);
+9
View File
@@ -725,6 +725,7 @@ MediaScanner::checkAudioFiles( Stats& stats )
{
Wt::Dbo::Transaction transaction(_db.getSession());
// TODO better query for this
// Now process orphan Cluster (no track)
auto clusters = Cluster::getAll(_db.getSession());
for (auto cluster : clusters)
@@ -735,6 +736,14 @@ MediaScanner::checkAudioFiles( Stats& stats )
cluster.remove();
}
}
// Now process orphan cluster types
auto clusterTypes = ClusterType::getAllOrphans(_db.getSession());
for (auto clusterType : clusterTypes)
{
LMS_LOG(DBUPDATER, DEBUG) << "Removing orphan cluster type '" << clusterType->getName() << "'";
clusterType.remove();
}
}
LMS_LOG(DBUPDATER, DEBUG) << "Checking artists...";