Fixed bad optimize condition

This commit is contained in:
emeric
2023-11-08 20:16:31 +01:00
parent 6bb6dd6add
commit c2e1c5d9df
@@ -40,7 +40,7 @@ namespace
Artist::pointer Artist::pointer
createArtist(Session& session, const MetaData::Artist& artistInfo) createArtist(Session& session, const MetaData::Artist& artistInfo)
{ {
Artist::pointer artist {session.create<Artist>(artistInfo.name)}; Artist::pointer artist{ session.create<Artist>(artistInfo.name) };
if (artistInfo.mbid) if (artistInfo.mbid)
artist.modify()->setMBID(*artistInfo.mbid); artist.modify()->setMBID(*artistInfo.mbid);
@@ -60,7 +60,7 @@ namespace
} }
// Sortname may have been updated // Sortname may have been updated
if (artistInfo.sortName && *artistInfo.sortName != artist->getSortName() ) if (artistInfo.sortName && *artistInfo.sortName != artist->getSortName())
{ {
artist.modify()->setSortName(*artistInfo.sortName); artist.modify()->setSortName(*artistInfo.sortName);
} }
@@ -185,7 +185,7 @@ namespace
release.modify()->setTotalDisc(releaseInfo.mediumCount); release.modify()->setTotalDisc(releaseInfo.mediumCount);
if (releaseInfo.primaryType) if (releaseInfo.primaryType)
{ {
const ReleaseTypePrimary primaryType {convertReleaseTypePrimary(*releaseInfo.primaryType)}; const ReleaseTypePrimary primaryType{ convertReleaseTypePrimary(*releaseInfo.primaryType) };
if (release->getPrimaryType() != primaryType) if (release->getPrimaryType() != primaryType)
release.modify()->setPrimaryType(primaryType); release.modify()->setPrimaryType(primaryType);
} }
@@ -263,7 +263,7 @@ namespace
MetaData::ParserReadStyle MetaData::ParserReadStyle
getParserReadStyle() getParserReadStyle()
{ {
std::string_view readStyle {Service<IConfig>::get()->getString("scanner-parser-read-style", "accurate")}; std::string_view readStyle{ Service<IConfig>::get()->getString("scanner-parser-read-style", "accurate") };
if (readStyle == "fast") if (readStyle == "fast")
return MetaData::ParserReadStyle::Fast; return MetaData::ParserReadStyle::Fast;
@@ -272,15 +272,15 @@ namespace
else if (readStyle == "accurate") else if (readStyle == "accurate")
return MetaData::ParserReadStyle::Accurate; return MetaData::ParserReadStyle::Accurate;
throw LmsException {"Invalid value for 'scanner-parser-read-style'"}; throw LmsException{ "Invalid value for 'scanner-parser-read-style'" };
} }
} // namespace } // namespace
namespace Scanner namespace Scanner
{ {
ScanStepScanFiles::ScanStepScanFiles(InitParams& initParams) ScanStepScanFiles::ScanStepScanFiles(InitParams& initParams)
: ScanStepBase {initParams} : ScanStepBase{ initParams }
, _metadataParser {MetaData::createParser(MetaData::ParserType::TagLib, getParserReadStyle())} // For now, always use TagLib , _metadataParser{ MetaData::createParser(MetaData::ParserType::TagLib, getParserReadStyle()) } // For now, always use TagLib
{ {
} }
@@ -299,7 +299,7 @@ namespace Scanner
if (ec) if (ec)
{ {
LMS_LOG(DBUPDATER, ERROR) << "Cannot process entry '" << path.string() << "': " << ec.message(); LMS_LOG(DBUPDATER, ERROR) << "Cannot process entry '" << path.string() << "': " << ec.message();
context.stats.errors.emplace_back(ScanError {path, ScanErrorType::CannotReadFile, ec.message()}); context.stats.errors.emplace_back(ScanError{ path, ScanErrorType::CannotReadFile, ec.message() });
} }
else if (PathUtils::hasFileAnyExtension(path, _settings.supportedExtensions)) else if (PathUtils::hasFileAnyExtension(path, _settings.supportedExtensions))
{ {
@@ -309,7 +309,7 @@ namespace Scanner
_progressCallback(context.currentStepStats); _progressCallback(context.currentStepStats);
// optimize the database during scan (if we import a very large database, it may be too late to do it once at end) // optimize the database during scan (if we import a very large database, it may be too late to do it once at end)
if ((context.stats.nbChanges() % 5'000) == 0) if ((context.currentStepStats.processedElems % 1'000) == 0)
_db.getTLSSession().optimize(); _db.getTLSSession().optimize();
} }
@@ -320,7 +320,7 @@ namespace Scanner
void void
ScanStepScanFiles::scanAudioFile(const std::filesystem::path& file, ScanContext& context) ScanStepScanFiles::scanAudioFile(const std::filesystem::path& file, ScanContext& context)
{ {
ScanStats& stats {context.stats}; ScanStats& stats{ context.stats };
Wt::WDateTime lastWriteTime; Wt::WDateTime lastWriteTime;
try try
{ {
@@ -336,10 +336,10 @@ namespace Scanner
if (!context.forceScan) if (!context.forceScan)
{ {
// Skip file if last write is the same // Skip file if last write is the same
Database::Session& dbSession {_db.getTLSSession()}; Database::Session& dbSession{ _db.getTLSSession() };
auto transaction {_db.getTLSSession().createSharedTransaction()}; auto transaction{ _db.getTLSSession().createSharedTransaction() };
const Track::pointer track {Track::findByPath(dbSession, file)}; const Track::pointer track{ Track::findByPath(dbSession, file) };
if (track && track->getLastWriteTime().toTime_t() == lastWriteTime.toTime_t() if (track && track->getLastWriteTime().toTime_t() == lastWriteTime.toTime_t()
&& track->getScanVersion() == _settings.scanVersion) && track->getScanVersion() == _settings.scanVersion)
@@ -349,7 +349,7 @@ namespace Scanner
} }
} }
std::optional<MetaData::Track> trackInfo {_metadataParser->parse(file)}; std::optional<MetaData::Track> trackInfo{ _metadataParser->parse(file) };
if (!trackInfo) if (!trackInfo)
{ {
context.stats.errors.emplace_back(file, ScanErrorType::CannotParseFile); context.stats.errors.emplace_back(file, ScanErrorType::CannotParseFile);
@@ -358,19 +358,19 @@ namespace Scanner
stats.scans++; stats.scans++;
Database::Session& dbSession {_db.getTLSSession()}; Database::Session& dbSession{ _db.getTLSSession() };
auto uniqueTransaction {dbSession.createUniqueTransaction()}; auto uniqueTransaction{ dbSession.createUniqueTransaction() };
Track::pointer track {Track::findByPath(dbSession, file) }; Track::pointer track{ Track::findByPath(dbSession, file) };
if (trackInfo->mbid && (!track || _settings.skipDuplicateMBID)) if (trackInfo->mbid && (!track || _settings.skipDuplicateMBID))
{ {
std::vector<Track::pointer> duplicateTracks {Track::findByMBID(dbSession, *trackInfo->mbid)}; std::vector<Track::pointer> duplicateTracks{ Track::findByMBID(dbSession, *trackInfo->mbid) };
// find for existing MBIDs as the file may have just been moved // find for existing MBIDs as the file may have just been moved
if (!track && duplicateTracks.size() == 1) if (!track && duplicateTracks.size() == 1)
{ {
Track::pointer otherTrack {duplicateTracks.front()}; Track::pointer otherTrack{ duplicateTracks.front() };
std::error_code ec; std::error_code ec;
if (!std::filesystem::exists(otherTrack->getPath(), ec)) if (!std::filesystem::exists(otherTrack->getPath(), ec))
{ {
@@ -418,7 +418,7 @@ namespace Scanner
track.remove(); track.remove();
stats.deletions++; stats.deletions++;
} }
stats.errors.emplace_back(ScanError {file, ScanErrorType::NoAudioTrack}); stats.errors.emplace_back(ScanError{ file, ScanErrorType::NoAudioTrack });
return; return;
} }
if (trackInfo->duration == std::chrono::milliseconds::zero()) if (trackInfo->duration == std::chrono::milliseconds::zero())
@@ -431,7 +431,7 @@ namespace Scanner
track.remove(); track.remove();
stats.deletions++; stats.deletions++;
} }
stats.errors.emplace_back(ScanError {file, ScanErrorType::BadDuration}); stats.errors.emplace_back(ScanError{ file, ScanErrorType::BadDuration });
return; return;
} }
@@ -525,7 +525,7 @@ namespace Scanner
track.modify()->setRecordingMBID(trackInfo->recordingMBID); track.modify()->setRecordingMBID(trackInfo->recordingMBID);
track.modify()->setTrackMBID(trackInfo->mbid); track.modify()->setTrackMBID(trackInfo->mbid);
if (auto trackFeatures {TrackFeatures::find(dbSession, track->getId())}) if (auto trackFeatures{ TrackFeatures::find(dbSession, track->getId()) })
trackFeatures.remove(); // TODO: only if MBID changed? trackFeatures.remove(); // TODO: only if MBID changed?
track.modify()->setHasCover(trackInfo->hasCover); track.modify()->setHasCover(trackInfo->hasCover);
track.modify()->setCopyright(trackInfo->copyright); track.modify()->setCopyright(trackInfo->copyright);