refactor: Clean up CThreadedReader

This commit is contained in:
Lars Toenning
2025-06-09 13:50:48 +02:00
parent b670ca4543
commit b553ef77c6
3 changed files with 6 additions and 40 deletions

View File

@@ -664,7 +664,7 @@ namespace swift::core::db
if (CEntityFlags::isSingleEntity(entity))
{
emit this->entityDownloadProgress(entity, logId, m_networkReplyProgress, m_networkReplyCurrent,
m_networkReplyNax, url);
m_networkReplyMax, url);
}
}

View File

@@ -34,8 +34,6 @@ namespace swift::core
m_updateTimer.setSingleShot(true);
}
CThreadedReader::~CThreadedReader() {}
qint64 CThreadedReader::lastModifiedMsSinceEpoch(QNetworkReply *nwReply) const
{
return CNetworkUtils::lastModifiedMsSinceEpoch(nwReply);
@@ -53,28 +51,12 @@ namespace swift::core
m_updateTimestamp = updateTimestamp;
}
bool CThreadedReader::updatedWithinLastMs(qint64 timeLastMs)
{
QDateTime dt(getUpdateTimestamp());
if (dt.isNull() || !dt.isValid()) { return false; }
qint64 delta = QDateTime::currentMSecsSinceEpoch() - dt.toMSecsSinceEpoch();
return delta <= timeLastMs;
}
void CThreadedReader::startReader()
{
Q_ASSERT(m_initialTime > 0);
QTimer::singleShot(m_initialTime, this, [=] { this->doWork(); });
}
void CThreadedReader::pauseReader() { QTimer::singleShot(0, &m_updateTimer, &QTimer::stop); }
bool CThreadedReader::hasPendingUrls() const
{
QReadLocker l(&m_lock);
return m_urlReadLog.hasPending();
}
CUrlLogList CThreadedReader::getUrlLogList() const
{
QReadLocker l(&m_lock);
@@ -170,7 +152,7 @@ namespace swift::core
QPair<qint64, qint64> CThreadedReader::getNetworkReplyBytes() const
{
return QPair<qint64, qint64>(m_networkReplyCurrent, m_networkReplyNax);
return QPair<qint64, qint64>(m_networkReplyCurrent, m_networkReplyMax);
}
void CThreadedReader::networkReplyProgress(int logId, qint64 current, qint64 max, const QUrl &url)
@@ -178,7 +160,7 @@ namespace swift::core
// max can be -1 if file size is not available
m_networkReplyProgress = (current > 0 && max > 0) ? static_cast<int>((current * 100) / max) : -1;
m_networkReplyCurrent = current;
m_networkReplyNax = max;
m_networkReplyMax = max;
Q_UNUSED(url);
Q_UNUSED(logId);

View File

@@ -37,7 +37,7 @@ namespace swift::core
static const QStringList &getLogCategories();
//! Destructor
virtual ~CThreadedReader();
virtual ~CThreadedReader() = default;
//! Thread safe, get update timestamp
//! \threadsafe
@@ -47,10 +47,6 @@ namespace swift::core
//! \threadsafe
void setUpdateTimestamp(const QDateTime &updateTimestamp = QDateTime::currentDateTimeUtc());
//! Was setup read within last xx milliseconds
//! \threadsafe
bool updatedWithinLastMs(qint64 timeLastMs);
//! Is marked as read failed
//! \threadsafe
//! \deprecated likely to be removed
@@ -69,26 +65,14 @@ namespace swift::core
//! \threadsafe
void startReader();
//! Pauses the reader
//! \threadsafe
void pauseReader();
//! Used in unit test
//! \remark needs to be done before started in different thread
void markAsUsedInUnitTest() { m_unitTest = true; }
//! Has pending URLs?
//! \threadsafe
bool hasPendingUrls() const;
//! Get the URL log list
//! \threadsafe
swift::misc::network::CUrlLogList getUrlLogList() const;
//! Progress 0..100
//! \threadsafe
int getNetworkReplyProgress() const { return m_networkReplyProgress; }
//! Max./current bytes
QPair<qint64, qint64> getNetworkReplyBytes() const;
@@ -98,7 +82,7 @@ namespace swift::core
}; //!< lock which can be used from the derived classes
std::atomic_int m_networkReplyProgress; //!< Progress percentage 0...100
std::atomic_llong m_networkReplyCurrent; //!< current bytes
std::atomic_llong m_networkReplyNax; //!< max bytes
std::atomic_llong m_networkReplyMax; //!< max bytes
//! Constructor
CThreadedReader(QObject *owner, const QString &name);
@@ -106,7 +90,7 @@ namespace swift::core
//! When was reply last modified, -1 if N/A
qint64 lastModifiedMsSinceEpoch(QNetworkReply *nwReply) const;
//! Make sure everthing runs correctly in own thread
//! Make sure everything runs correctly in own thread
void threadAssertCheck() const;
//! Stores new content hash and returns if content changed (based on hash value