From 682e4f2c2bd6bda2750f61a3046127c3dd83b3e5 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Sat, 21 Oct 2023 22:23:08 -0500 Subject: [PATCH] refactor: make tr_torrent::any_date_ private (#6148) --- libtransmission/rpcimpl.cc | 2 +- libtransmission/torrent.cc | 8 ++++---- libtransmission/torrent.h | 25 ++++++++++++++++++------- 3 files changed, 23 insertions(+), 12 deletions(-) diff --git a/libtransmission/rpcimpl.cc b/libtransmission/rpcimpl.cc index e4f8ffc15..1cd81778f 100644 --- a/libtransmission/rpcimpl.cc +++ b/libtransmission/rpcimpl.cc @@ -133,7 +133,7 @@ auto getTorrents(tr_session* session, tr_variant* args) std::begin(session->torrents()), std::end(session->torrents()), std::back_inserter(torrents), - [&cutoff](auto const* tor) { return tor->anyDate >= cutoff; }); + [&cutoff](auto const* tor) { return tor->has_changed_since(cutoff); }); } else { diff --git a/libtransmission/torrent.cc b/libtransmission/torrent.cc index d8c8c9ee1..d0464eb1c 100644 --- a/libtransmission/torrent.cc +++ b/libtransmission/torrent.cc @@ -1021,9 +1021,9 @@ void tr_torrent::init(tr_ctor const* const ctor) TR_ASSERT(downloadedCur == 0); TR_ASSERT(uploadedCur == 0); - auto const now = tr_time(); - addedDate = now; // this is a default that will be overwritten by the resume file - anyDate = now; + mark_changed(); + + addedDate = tr_time(); // this is a default that will be overwritten by the resume file tr_resume::fields_t loaded = {}; @@ -2620,7 +2620,7 @@ void tr_torrent::mark_edited() void tr_torrent::mark_changed() { - this->anyDate = tr_time(); + this->bump_date_changed(tr_time()); } void tr_torrent::set_blocks(tr_bitfield blocks) diff --git a/libtransmission/torrent.h b/libtransmission/torrent.h index 81d79abd0..8e6c59849 100644 --- a/libtransmission/torrent.h +++ b/libtransmission/torrent.h @@ -621,14 +621,11 @@ public: unique_id_ = id; } - constexpr void set_date_active(time_t t) noexcept + constexpr void set_date_active(time_t when) noexcept { - this->activityDate = t; + this->activityDate = when; - if (this->anyDate < t) - { - this->anyDate = t; - } + bump_date_changed(when); } [[nodiscard]] constexpr auto activity() const noexcept @@ -705,6 +702,11 @@ public: void mark_edited(); void mark_changed(); + [[nodiscard]] constexpr auto has_changed_since(time_t when) const noexcept + { + return changed_date_ > when; + } + void set_bandwidth_group(std::string_view group_name) noexcept; [[nodiscard]] constexpr auto get_priority() const noexcept @@ -966,7 +968,6 @@ public: time_t activityDate = 0; time_t addedDate = 0; - time_t anyDate = 0; time_t doneDate = 0; time_t editDate = 0; time_t startDate = 0; @@ -1149,6 +1150,14 @@ private: } } + constexpr void bump_date_changed(time_t when) + { + if (changed_date_ < when) + { + changed_date_ = when; + } + } + void set_verify_state(VerifyState state); void on_metainfo_updated(); @@ -1175,6 +1184,8 @@ private: */ tr_peer_id_t peer_id_ = tr_peerIdInit(); + time_t changed_date_ = 0; + float verify_progress_ = -1.0F; float seed_ratio_ = 0.0F;