mirror of
https://github.com/qbittorrent/qBittorrent
synced 2025-08-20 21:33:27 -07:00
Improve "last activity" calculation in WebAPI (#15339)
Co-authored-by: 秦风 <mayli.he@gmail.com> Co-authored-by: Chocobo1 <Chocobo1@users.noreply.github.com>
This commit is contained in:
parent
84ec5a6acf
commit
250cac73b6
1 changed files with 6 additions and 5 deletions
|
@ -95,11 +95,12 @@ QVariantMap serialize(const BitTorrent::Torrent &torrent)
|
||||||
return (ratio > BitTorrent::Torrent::MAX_RATIO) ? -1 : ratio;
|
return (ratio > BitTorrent::Torrent::MAX_RATIO) ? -1 : ratio;
|
||||||
};
|
};
|
||||||
|
|
||||||
const auto adjustLastActivity = [&torrent](const qlonglong value) -> qlonglong
|
const auto getLastActivityTime = [&torrent]() -> qlonglong
|
||||||
{
|
{
|
||||||
return (torrent.isPaused() || torrent.isChecking())
|
const qlonglong timeSinceActivity = torrent.timeSinceActivity();
|
||||||
? 0
|
return (timeSinceActivity < 0)
|
||||||
: (QDateTime::currentDateTime().toSecsSinceEpoch() - value);
|
? torrent.addedTime().toSecsSinceEpoch()
|
||||||
|
: (QDateTime::currentDateTime().toSecsSinceEpoch() - timeSinceActivity);
|
||||||
};
|
};
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
@ -149,7 +150,7 @@ QVariantMap serialize(const BitTorrent::Torrent &torrent)
|
||||||
{KEY_TORRENT_AUTO_TORRENT_MANAGEMENT, torrent.isAutoTMMEnabled()},
|
{KEY_TORRENT_AUTO_TORRENT_MANAGEMENT, torrent.isAutoTMMEnabled()},
|
||||||
{KEY_TORRENT_TIME_ACTIVE, torrent.activeTime()},
|
{KEY_TORRENT_TIME_ACTIVE, torrent.activeTime()},
|
||||||
{KEY_TORRENT_SEEDING_TIME, torrent.seedingTime()},
|
{KEY_TORRENT_SEEDING_TIME, torrent.seedingTime()},
|
||||||
{KEY_TORRENT_LAST_ACTIVITY_TIME, adjustLastActivity(torrent.timeSinceActivity())},
|
{KEY_TORRENT_LAST_ACTIVITY_TIME, getLastActivityTime()},
|
||||||
{KEY_TORRENT_AVAILABILITY, torrent.distributedCopies()},
|
{KEY_TORRENT_AVAILABILITY, torrent.distributedCopies()},
|
||||||
|
|
||||||
{KEY_TORRENT_TOTAL_SIZE, torrent.totalSize()}
|
{KEY_TORRENT_TOTAL_SIZE, torrent.totalSize()}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue