mirror of
https://github.com/clangen/musikcube.git
synced 2025-03-14 13:21:13 +00:00
Ensure we're always querying file modified date from the DB as int64
(not int32) to ensure we're not indexing files that don't need to be.
This commit is contained in:
parent
a1181f2f87
commit
54952980dd
@ -1078,13 +1078,13 @@ void Indexer::CommitProgress(IIndexerSource* source, unsigned updatedTracks) {
|
||||
}
|
||||
}
|
||||
|
||||
int Indexer::GetLastModifiedTime(IIndexerSource* source, const char* externalId) {
|
||||
int64_t Indexer::GetLastModifiedTime(IIndexerSource* source, const char* externalId) {
|
||||
if (source && externalId && strlen(externalId)) {
|
||||
db::Statement stmt("SELECT filetime FROM tracks t where source_id=? AND external_id=?", dbConnection);
|
||||
stmt.BindInt32(0, source->SourceId());
|
||||
stmt.BindText(1, externalId);
|
||||
if (stmt.Step() == db::Row) {
|
||||
return stmt.ColumnInt32(0);
|
||||
return stmt.ColumnInt64(0);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -90,7 +90,7 @@ namespace musik { namespace core {
|
||||
bool RemoveByExternalId(musik::core::sdk::IIndexerSource* source, const char* id) override;
|
||||
int RemoveAll(musik::core::sdk::IIndexerSource* source) override;
|
||||
void CommitProgress(musik::core::sdk::IIndexerSource* source, unsigned updatedTracks) override;
|
||||
int GetLastModifiedTime(musik::core::sdk::IIndexerSource* source, const char* id) override;
|
||||
int64_t GetLastModifiedTime(musik::core::sdk::IIndexerSource* source, const char* id) override;
|
||||
|
||||
bool Save(
|
||||
musik::core::sdk::IIndexerSource* source,
|
||||
|
@ -271,7 +271,7 @@ bool IndexerTrack::NeedsToBeIndexed(
|
||||
}
|
||||
|
||||
const size_t fileSize = (size_t) std::filesystem::file_size(file);
|
||||
const size_t fileTime = (size_t)duration_cast<milliseconds>(
|
||||
const int64_t fileTime = (int64_t) duration_cast<milliseconds>(
|
||||
std::filesystem::last_write_time(file).time_since_epoch()).count();
|
||||
|
||||
this->SetValue("filesize", std::to_string(fileSize).c_str());
|
||||
@ -289,7 +289,7 @@ bool IndexerTrack::NeedsToBeIndexed(
|
||||
if (stmt.Step() == db::Row) {
|
||||
this->trackId = stmt.ColumnInt64(0);
|
||||
const int dbFileSize = stmt.ColumnInt32(2);
|
||||
const int dbFileTime = stmt.ColumnInt32(3);
|
||||
const int64_t dbFileTime = stmt.ColumnInt64(3);
|
||||
|
||||
if (fileSize == dbFileSize && fileTime == dbFileTime) {
|
||||
return false;
|
||||
@ -359,6 +359,8 @@ static int64_t writeToTracksTable(
|
||||
|
||||
db::Statement stmt(query.c_str(), dbConnection);
|
||||
|
||||
auto time = track.GetInt64("filetime");
|
||||
|
||||
stmt.BindInt32(0, stringToInt(track.GetString("track"), 1));
|
||||
stmt.BindInt32(1, stringToInt(track.GetString("disc"), 1));
|
||||
stmt.BindText(2, track.GetString("bpm"));
|
||||
|
@ -43,6 +43,8 @@
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <functional>
|
||||
#include <chrono>
|
||||
#include <filesystem>
|
||||
#include "String.h"
|
||||
|
||||
#ifdef WIN32
|
||||
@ -69,21 +71,9 @@ namespace musik { namespace core { namespace sdk { namespace fs {
|
||||
}
|
||||
|
||||
template <typename String=std::string>
|
||||
static int getLastModifiedTime(const String& fn) {
|
||||
#ifdef WIN32
|
||||
/* todo */
|
||||
struct _stat result = { 0 };
|
||||
std::wstring fn16 = musik::core::sdk::str::u8to16(fn.c_str());
|
||||
if (_wstat(fn16.c_str(), &result) == 0) {
|
||||
return (int)result.st_mtime;
|
||||
}
|
||||
#else
|
||||
struct stat result = { 0 };
|
||||
if (stat(fn.c_str(), &result) == 0) {
|
||||
return result.st_mtime;
|
||||
}
|
||||
#endif
|
||||
return -1;
|
||||
static int64_t getLastModifiedTime(const String& fn) {
|
||||
return (int64_t) std::chrono::duration_cast<std::chrono::milliseconds>(
|
||||
std::filesystem::last_write_time(std::filesystem::u8path(fn)).time_since_epoch()).count();
|
||||
}
|
||||
|
||||
template <typename String=std::string>
|
||||
|
@ -48,7 +48,7 @@ namespace musik { namespace core { namespace sdk {
|
||||
virtual bool RemoveByUri(IIndexerSource* source, const char* uri) = 0;
|
||||
virtual bool RemoveByExternalId(IIndexerSource* source, const char* id) = 0;
|
||||
virtual int RemoveAll(IIndexerSource* source) = 0;
|
||||
virtual int GetLastModifiedTime(IIndexerSource* source, const char* externalId) = 0;
|
||||
virtual int64_t GetLastModifiedTime(IIndexerSource* source, const char* externalId) = 0;
|
||||
};
|
||||
|
||||
} } }
|
||||
|
@ -150,9 +150,9 @@ void GmeIndexerSource::UpdateMetadata(
|
||||
{
|
||||
/* only need to do this check once, and it's relatively expensive because
|
||||
it requires a db read. cache we've already done it. */
|
||||
int modifiedTime = fs::getLastModifiedTime(fn);
|
||||
int64_t modifiedTime = fs::getLastModifiedTime(fn);
|
||||
const std::string firstExternalId = indexer::createExternalId(EXTERNAL_ID_PREFIX, fn, 0);
|
||||
int modifiedDbTime = indexer->GetLastModifiedTime(this, firstExternalId.c_str());
|
||||
int64_t modifiedDbTime = indexer->GetLastModifiedTime(this, firstExternalId.c_str());
|
||||
if (modifiedDbTime < 0 || modifiedTime != modifiedDbTime) {
|
||||
fn = fs::canonicalizePath(fn);
|
||||
|
||||
|
@ -171,9 +171,9 @@ void OpenMptIndexerSource::UpdateMetadata(
|
||||
{
|
||||
/* only need to do this check once, and it's relatively expensive because
|
||||
it requires a db read. cache we've already done it. */
|
||||
int modifiedTime = fs::getLastModifiedTime(fn);
|
||||
int64_t modifiedTime = fs::getLastModifiedTime(fn);
|
||||
const std::string firstExternalId = indexer::createExternalId(PLUGIN_NAME, fn, 0);
|
||||
int modifiedDbTime = indexer->GetLastModifiedTime(this, firstExternalId.c_str());
|
||||
int64_t modifiedDbTime = indexer->GetLastModifiedTime(this, firstExternalId.c_str());
|
||||
if (modifiedDbTime < 0 || modifiedTime != modifiedDbTime) {
|
||||
fn = fs::canonicalizePath(fn);
|
||||
char* fileBytes = nullptr;
|
||||
|
Loading…
x
Reference in New Issue
Block a user