mirror of
https://github.com/transmission/transmission
synced 2025-01-03 05:25:52 +00:00
fix: in RPC, default to sort torrents by id (#5604)
When getting all torrents in a batch over RPC, the results are sorted by info-dict hash. Prior to 4.0.0, they were sorted by ID. This change broke some peoples' workflows. I'm OK with breaking workflows if it's necessary to improve the program, but this was an unintentional side-effect and I don't see any inherent benefit to either sort order. So this PR restores the 3.00 sort order. https://xkcd.com/1172/
This commit is contained in:
parent
5a6f0a5623
commit
901de536a3
2 changed files with 11 additions and 5 deletions
|
@ -128,10 +128,11 @@ auto getTorrents(tr_session* session, tr_variant* args)
|
|||
{
|
||||
time_t const cutoff = tr_time() - RecentlyActiveSeconds;
|
||||
|
||||
torrents.reserve(std::size(session->torrents()));
|
||||
auto const& by_id = session->torrents().sorted_by_id();
|
||||
torrents.reserve(std::size(by_id));
|
||||
std::copy_if(
|
||||
std::begin(session->torrents()),
|
||||
std::end(session->torrents()),
|
||||
std::begin(by_id),
|
||||
std::end(by_id),
|
||||
std::back_inserter(torrents),
|
||||
[&cutoff](auto const* tor) { return tor->has_changed_since(cutoff); });
|
||||
}
|
||||
|
@ -146,8 +147,8 @@ auto getTorrents(tr_session* session, tr_variant* args)
|
|||
}
|
||||
else // all of them
|
||||
{
|
||||
torrents.reserve(std::size(session->torrents()));
|
||||
std::copy(std::begin(session->torrents()), std::end(session->torrents()), std::back_inserter(torrents));
|
||||
auto const& by_id = session->torrents().sorted_by_id();
|
||||
torrents = std::vector<tr_torrent*>{ std::begin(by_id), std::end(by_id) };
|
||||
}
|
||||
|
||||
return torrents;
|
||||
|
|
|
@ -107,6 +107,11 @@ public:
|
|||
return std::empty(by_hash_);
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr auto const& sorted_by_id() const noexcept
|
||||
{
|
||||
return by_id_;
|
||||
}
|
||||
|
||||
private:
|
||||
std::vector<tr_torrent*> by_hash_;
|
||||
|
||||
|
|
Loading…
Reference in a new issue