Browse Source

Improve "last activity" calculation in WebAPI (#15339)

Co-authored-by: 秦风 <mayli.he@gmail.com>

Co-authored-by: Chocobo1 <Chocobo1@users.noreply.github.com>
adaptive-webui-19844
Chocobo1 3 years ago committed by GitHub
parent
commit
8d822f2cb4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 10
      src/webui/api/serialize/serialize_torrent.cpp

10
src/webui/api/serialize/serialize_torrent.cpp

@ -97,6 +97,14 @@ QVariantMap serialize(const BitTorrent::Torrent &torrent) @@ -97,6 +97,14 @@ QVariantMap serialize(const BitTorrent::Torrent &torrent)
return (ratio > BitTorrent::Torrent::MAX_RATIO) ? -1 : ratio;
};
const auto getLastActivityTime = [&torrent]() -> qlonglong
{
const qlonglong timeSinceActivity = torrent.timeSinceActivity();
return (timeSinceActivity < 0)
? torrent.addedTime().toSecsSinceEpoch()
: (QDateTime::currentDateTime().toSecsSinceEpoch() - timeSinceActivity);
};
return {
{KEY_TORRENT_ID, torrent.id().toString()},
{KEY_TORRENT_INFOHASHV1, torrent.infoHash().v1().toString()},
@ -145,7 +153,7 @@ QVariantMap serialize(const BitTorrent::Torrent &torrent) @@ -145,7 +153,7 @@ QVariantMap serialize(const BitTorrent::Torrent &torrent)
{KEY_TORRENT_AUTO_TORRENT_MANAGEMENT, torrent.isAutoTMMEnabled()},
{KEY_TORRENT_TIME_ACTIVE, torrent.activeTime()},
{KEY_TORRENT_SEEDING_TIME, torrent.seedingTime()},
{KEY_TORRENT_LAST_ACTIVITY_TIME, (QDateTime::currentDateTime().toSecsSinceEpoch() - torrent.timeSinceActivity())},
{KEY_TORRENT_LAST_ACTIVITY_TIME, getLastActivityTime()},
{KEY_TORRENT_AVAILABILITY, torrent.distributedCopies()},
{KEY_TORRENT_TOTAL_SIZE, torrent.totalSize()}

Loading…
Cancel
Save