diff options
| author | Silarn <jrim@rimpo.org> | 2019-02-05 16:53:54 -0600 |
|---|---|---|
| committer | Silarn <jrim@rimpo.org> | 2019-02-18 21:31:19 -0600 |
| commit | d86d2f704ab0eb91a9051fa818b5195f323467fa (patch) | |
| tree | 9af499b51726fc323037e573be2d2f4e519dbc21 /src/modinforegular.cpp | |
| parent | a873c7be23f270ab1a929aaf72aa03182e0ddc2c (diff) | |
Implement staggered timeouts bases on age.
* < 1 mo = 2 hours
* < 3 mo = 4 hours
* < 6 mo = 6 hours
* < 1 yr = 12 hours
* > 1 yr = 24 hours
Diffstat (limited to 'src/modinforegular.cpp')
| -rw-r--r-- | src/modinforegular.cpp | 37 |
1 files changed, 36 insertions, 1 deletions
diff --git a/src/modinforegular.cpp b/src/modinforegular.cpp index 8651f15e..876ccf3d 100644 --- a/src/modinforegular.cpp +++ b/src/modinforegular.cpp @@ -100,6 +100,7 @@ void ModInfoRegular::readMeta() m_URL = metaFile.value("url", "").toString(); m_LastNexusQuery = QDateTime::fromString(metaFile.value("lastNexusQuery", "").toString(), Qt::ISODate); m_LastNexusUpdate = QDateTime::fromString(metaFile.value("lastNexusUpdate", "").toString(), Qt::ISODate); + m_NexusLastModified = QDateTime::fromString(metaFile.value("nexusLastModified", QDateTime::currentDateTimeUtc()).toString(), Qt::ISODate); m_Color = metaFile.value("color",QColor()).value<QColor>(); if (metaFile.contains("endorsed")) { if (metaFile.value("endorsed").canConvert<int>()) { @@ -165,6 +166,7 @@ void ModInfoRegular::saveMeta() metaFile.setValue("nexusFileStatus", m_NexusFileStatus); metaFile.setValue("lastNexusQuery", m_LastNexusQuery.toString(Qt::ISODate)); metaFile.setValue("lastNexusUpdate", m_LastNexusUpdate.toString(Qt::ISODate)); + metaFile.setValue("nexusLastModified", m_NexusLastModified.toString(Qt::ISODate)); metaFile.setValue("converted", m_Converted); metaFile.setValue("validated", m_Validated); metaFile.setValue("color", m_Color); @@ -233,6 +235,7 @@ void ModInfoRegular::nxmDescriptionAvailable(QString, int, QVariant, QVariant re setEndorsedState(ENDORSED_FALSE); } m_LastNexusQuery = QDateTime::currentDateTimeUtc(); + m_NexusLastModified = QDateTime::fromSecsSinceEpoch(result["updated_timestamp"].toInt()); m_MetaInfoChanged = true; saveMeta(); disconnect(sender(), SIGNAL(nxmDescriptionAvailable(QString, int, QVariant, QVariant))); @@ -496,12 +499,31 @@ void ModInfoRegular::ignoreUpdate(bool ignore) bool ModInfoRegular::canBeUpdated() const { QDateTime now = QDateTime::currentDateTimeUtc(); - QDateTime target = m_LastNexusUpdate.addSecs(3600); + QDateTime target = getExpires(); if (now >= target) return m_NexusID > 0; return false; } +QDateTime ModInfoRegular::getExpires() const +{ + qint64 diff = m_NexusLastModified.msecsTo(QDateTime::currentDateTimeUtc()); + qint64 year = 31536000000; + qint64 sixMonths = 15768000000; + qint64 threeMonths = 7884000000; + qint64 oneMonth = 1314000000; + + if (diff < oneMonth) + return m_LastNexusUpdate.addSecs(7200); + else if (diff < threeMonths) + return m_LastNexusUpdate.addSecs(14400); + else if (diff < sixMonths) + return m_LastNexusUpdate.addSecs(21600); + else if (diff < year) + return m_LastNexusUpdate.addSecs(43200); + else + return m_LastNexusUpdate.addSecs(86400); +} std::vector<ModInfo::EFlag> ModInfoRegular::getFlags() const { @@ -686,6 +708,19 @@ void ModInfoRegular::setLastNexusQuery(QDateTime time) emit modDetailsUpdated(true); } +QDateTime ModInfoRegular::getNexusLastModified() const +{ + return m_NexusLastModified; +} + +void ModInfoRegular::setNexusLastModified(QDateTime time) +{ + m_NexusLastModified = time; + m_MetaInfoChanged = true; + saveMeta(); + emit modDetailsUpdated(true); +} + void ModInfoRegular::setURL(QString const &url) { m_URL = url; |
