Add a scan version field for each scanned track

This commit is contained in:
emeric
2018-05-24 14:08:13 +02:00
parent ed17769808
commit a087f470a7
5 changed files with 40 additions and 26 deletions
+6
View File
@@ -77,6 +77,7 @@ ScanSettings::setMediaDirectory(boost::filesystem::path p)
void void
ScanSettings::setClusterTypes(const std::set<std::string>& clusterTypeNames) ScanSettings::setClusterTypes(const std::set<std::string>& clusterTypeNames)
{ {
bool needRescan = false;
assert(session()); assert(session());
// Backup the old list // Backup the old list
@@ -91,6 +92,7 @@ ScanSettings::setClusterTypes(const std::set<std::string>& clusterTypeNames)
{ {
LMS_LOG(DB, INFO) << "Creating cluster type " << clusterTypeName; LMS_LOG(DB, INFO) << "Creating cluster type " << clusterTypeName;
clusterType = ClusterType::create(*session(), clusterTypeName); clusterType = ClusterType::create(*session(), clusterTypeName);
needRescan = true;
} }
_clusterTypes.insert(clusterType); _clusterTypes.insert(clusterType);
} }
@@ -103,8 +105,12 @@ ScanSettings::setClusterTypes(const std::set<std::string>& clusterTypeNames)
{ {
LMS_LOG(DB, INFO) << "Deleting cluster type " << oldClusterType->getName(); LMS_LOG(DB, INFO) << "Deleting cluster type " << oldClusterType->getName();
oldClusterType.remove(); oldClusterType.remove();
needRescan = true;
} }
} }
if (needRescan)
_scanVersion += 1;
} }
} // namespace Database } // namespace Database
+3
View File
@@ -44,6 +44,7 @@ class ScanSettings : public Wt::Dbo::Dbo<ScanSettings>
static pointer get(Wt::Dbo::Session& session); static pointer get(Wt::Dbo::Session& session);
// Getters // Getters
std::size_t getScanVersion() const { return _scanVersion; }
boost::filesystem::path getMediaDirectory() const { return _mediaDirectory; } boost::filesystem::path getMediaDirectory() const { return _mediaDirectory; }
Wt::WTime getUpdateStartTime() const { return _startTime; } Wt::WTime getUpdateStartTime() const { return _startTime; }
UpdatePeriod getUpdatePeriod() const { return _updatePeriod; } UpdatePeriod getUpdatePeriod() const { return _updatePeriod; }
@@ -60,6 +61,7 @@ class ScanSettings : public Wt::Dbo::Dbo<ScanSettings>
template<class Action> template<class Action>
void persist(Action& a) void persist(Action& a)
{ {
Wt::Dbo::field(a, _scanVersion, "scan_version");
Wt::Dbo::field(a, _mediaDirectory, "media_directory"); Wt::Dbo::field(a, _mediaDirectory, "media_directory");
Wt::Dbo::field(a, _startTime, "start_time"); Wt::Dbo::field(a, _startTime, "start_time");
Wt::Dbo::field(a, _updatePeriod, "update_period"); Wt::Dbo::field(a, _updatePeriod, "update_period");
@@ -69,6 +71,7 @@ class ScanSettings : public Wt::Dbo::Dbo<ScanSettings>
private: private:
int _scanVersion = 0;
std::string _mediaDirectory = ""; std::string _mediaDirectory = "";
Wt::WTime _startTime = Wt::WTime(0,0,0); Wt::WTime _startTime = Wt::WTime(0,0,0);
UpdatePeriod _updatePeriod = UpdatePeriod::Never; UpdatePeriod _updatePeriod = UpdatePeriod::Never;
+21 -17
View File
@@ -81,6 +81,7 @@ class Track : public Wt::Dbo::Dbo<Track>
static void removeClusters(std::string type); static void removeClusters(std::string type);
// Accessors // Accessors
void setScanVersion(std::size_t version) {_scanVersion = version; }
void setTrackNumber(int num) { _trackNumber = num; } void setTrackNumber(int num) { _trackNumber = num; }
void setTotalTrackNumber(int num) { _totalTrackNumber = num; } void setTotalTrackNumber(int num) { _totalTrackNumber = num; }
void setDiscNumber(int num) { _discNumber = num; } void setDiscNumber(int num) { _discNumber = num; }
@@ -98,29 +99,31 @@ class Track : public Wt::Dbo::Dbo<Track>
void setArtist(Wt::Dbo::ptr<Artist> artist) { _artist = artist; } void setArtist(Wt::Dbo::ptr<Artist> artist) { _artist = artist; }
void setRelease(Wt::Dbo::ptr<Release> release) { _release = release; } void setRelease(Wt::Dbo::ptr<Release> release) { _release = release; }
boost::optional<std::size_t> getTrackNumber(void) const; std::size_t getScanVersion() const { return _scanVersion; }
boost::optional<std::size_t> getTotalTrackNumber(void) const; boost::optional<std::size_t> getTrackNumber() const;
boost::optional<std::size_t> getDiscNumber(void) const; boost::optional<std::size_t> getTotalTrackNumber() const;
boost::optional<std::size_t> getTotalDiscNumber(void) const; boost::optional<std::size_t> getDiscNumber() const;
std::string getName(void) const { return _name; } boost::optional<std::size_t> getTotalDiscNumber() const;
boost::filesystem::path getPath(void) const { return _filePath; } std::string getName() const { return _name; }
std::chrono::milliseconds getDuration(void) const { return _duration; } boost::filesystem::path getPath() const { return _filePath; }
boost::optional<int> getYear(void) const; std::chrono::milliseconds getDuration() const { return _duration; }
boost::optional<int> getOriginalYear(void) const; boost::optional<int> getYear() const;
Wt::WDateTime getLastWriteTime(void) const { return _fileLastWrite; } boost::optional<int> getOriginalYear() const;
Wt::WDateTime getAddedTime(void) const { return _fileAdded; } Wt::WDateTime getLastWriteTime() const { return _fileLastWrite; }
const std::vector<unsigned char>& getChecksum(void) const { return _fileChecksum; } Wt::WDateTime getAddedTime() const { return _fileAdded; }
CoverType getCoverType(void) const { return _coverType; } const std::vector<unsigned char>& getChecksum() const { return _fileChecksum; }
const std::string& getMBID(void) const { return _MBID; } CoverType getCoverType() const { return _coverType; }
Wt::Dbo::ptr<Artist> getArtist(void) const { return _artist; } const std::string& getMBID() const { return _MBID; }
Wt::Dbo::ptr<Release> getRelease(void) const { return _release; } Wt::Dbo::ptr<Artist> getArtist() const { return _artist; }
std::vector<Wt::Dbo::ptr<Cluster>> getClusters(void) const; Wt::Dbo::ptr<Release> getRelease() const { return _release; }
std::vector<Wt::Dbo::ptr<Cluster>> getClusters() const;
std::vector<std::vector<Wt::Dbo::ptr<Cluster>>> getClusterGroups(std::vector<Wt::Dbo::ptr<ClusterType>> clusterTypes, std::size_t size) const; std::vector<std::vector<Wt::Dbo::ptr<Cluster>>> getClusterGroups(std::vector<Wt::Dbo::ptr<ClusterType>> clusterTypes, std::size_t size) const;
template<class Action> template<class Action>
void persist(Action& a) void persist(Action& a)
{ {
Wt::Dbo::field(a, _scanVersion, "scan_version");
Wt::Dbo::field(a, _trackNumber, "track_number"); Wt::Dbo::field(a, _trackNumber, "track_number");
Wt::Dbo::field(a, _totalTrackNumber, "total_track_number"); Wt::Dbo::field(a, _totalTrackNumber, "total_track_number");
Wt::Dbo::field(a, _discNumber, "disc_number"); Wt::Dbo::field(a, _discNumber, "disc_number");
@@ -146,6 +149,7 @@ class Track : public Wt::Dbo::Dbo<Track>
static const std::size_t _maxNameLength = 128; static const std::size_t _maxNameLength = 128;
int _scanVersion = 0;
int _trackNumber = 0; int _trackNumber = 0;
int _totalTrackNumber = 0; int _totalTrackNumber = 0;
int _discNumber = 0; int _discNumber = 0;
+9 -9
View File
@@ -345,6 +345,7 @@ MediaScanner::refreshScanSettings()
auto scanSettings = ScanSettings::get(_db.getSession()); auto scanSettings = ScanSettings::get(_db.getSession());
_scanVersion = scanSettings->getScanVersion();
_startTime = scanSettings->getUpdateStartTime(); _startTime = scanSettings->getUpdateStartTime();
_updatePeriod = scanSettings->getUpdatePeriod(); _updatePeriod = scanSettings->getUpdatePeriod();
@@ -369,16 +370,14 @@ MediaScanner::scanAudioFile(const boost::filesystem::path& file, bool forceScan,
if (!forceScan) if (!forceScan)
{ {
// Skip file if last write is the same // Skip file if last write is the same
Wt::Dbo::Transaction transaction(_db.getSession());
Wt::Dbo::ptr<Track> track = Track::getByPath(_db.getSession(), file);
if (track && track->getLastWriteTime() == lastWriteTime && track->getScanVersion() == _scanVersion)
{ {
Wt::Dbo::Transaction transaction(_db.getSession()); stats.skips++;
return;
Wt::Dbo::ptr<Track> track = Track::getByPath(_db.getSession(), file);
if (track && track->getLastWriteTime() == lastWriteTime)
{
stats.skips++;
return;
}
} }
} }
@@ -508,6 +507,7 @@ MediaScanner::scanAudioFile(const boost::filesystem::path& file, bool forceScan,
assert(track); assert(track);
track.modify()->setScanVersion(_scanVersion);
track.modify()->setChecksum(checksum); track.modify()->setChecksum(checksum);
track.modify()->setArtist(artist); track.modify()->setArtist(artist);
track.modify()->setRelease(release); track.modify()->setRelease(release);
+1
View File
@@ -97,6 +97,7 @@ class MediaScanner
Database::Handler _db; Database::Handler _db;
// Current scan settings // Current scan settings
std::size_t _scanVersion;
Wt::WTime _startTime; Wt::WTime _startTime;
Database::ScanSettings::UpdatePeriod _updatePeriod; Database::ScanSettings::UpdatePeriod _updatePeriod;
std::set<boost::filesystem::path> _fileExtensions; std::set<boost::filesystem::path> _fileExtensions;