Better handler ClusterType creation

This commit is contained in:
emeric
2018-03-04 15:52:16 +01:00
parent 3ac4d1b4f3
commit bbb988266d
+4 -7
View File
@@ -385,18 +385,15 @@ MediaScanner::getClusters( const MetaData::Clusters& clustersNames)
for (auto clusterNames : clustersNames)
{
ClusterType::pointer clusterType = ClusterType::getByName(_db.getSession(), clusterNames.first);
bool newType = !clusterType;
if (!clusterType)
{
clusterType = ClusterType::create(_db.getSession(), clusterNames.first);
_db.getSession().flush(); // Make sure the newly createdType has an id
}
std::cout << "Cluster type = " << clusterType.id() << "\n";
for (auto clusterName : clusterNames.second)
{
Cluster::pointer cluster;
if (!newType)
cluster = clusterType->getCluster(clusterName);
Cluster::pointer cluster = clusterType->getCluster(clusterName);
if (!cluster)
cluster = Cluster::create(_db.getSession(), clusterType, clusterName);