mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2025-06-27 17:09:53 -04:00
WebAPI: add new method setTags to upsert tags on torrents
This is another optimization for torrent management on large scale instances with the goal to minimize the amount of required API calls. Ref #22128. This new function and endpoint torrents/setTags does an upsert to replace the torrent tags and handles the removal and add internally, instead of doing multiple calls to add and remove tags on torrents from the client. PR #22156. --------- Co-authored-by: Chocobo1 <Chocobo1@users.noreply.github.com> Co-authored-by: Vladimir Golovnev <glassez@yandex.ru>
This commit is contained in:
parent
05787d94ec
commit
82c36aea89
3 changed files with 24 additions and 1 deletions
|
@ -1496,6 +1496,27 @@ void TorrentsController::addTagsAction()
|
|||
}
|
||||
}
|
||||
|
||||
void TorrentsController::setTagsAction()
|
||||
{
|
||||
requireParams({u"hashes"_s, u"tags"_s});
|
||||
|
||||
const QStringList hashes {params()[u"hashes"_s].split(u'|', Qt::SkipEmptyParts)};
|
||||
const QStringList tags {params()[u"tags"_s].split(u',', Qt::SkipEmptyParts)};
|
||||
|
||||
const TagSet newTags {tags.begin(), tags.end()};
|
||||
applyToTorrents(hashes, [&newTags](BitTorrent::Torrent *const torrent)
|
||||
{
|
||||
TagSet tmpTags {newTags};
|
||||
for (const Tag &tag : asConst(torrent->tags()))
|
||||
{
|
||||
if (tmpTags.erase(tag) == 0)
|
||||
torrent->removeTag(tag);
|
||||
}
|
||||
for (const Tag &tag : tmpTags)
|
||||
torrent->addTag(tag);
|
||||
});
|
||||
}
|
||||
|
||||
void TorrentsController::removeTagsAction()
|
||||
{
|
||||
requireParams({u"hashes"_s});
|
||||
|
|
|
@ -61,6 +61,7 @@ private slots:
|
|||
void removeCategoriesAction();
|
||||
void categoriesAction();
|
||||
void addTagsAction();
|
||||
void setTagsAction();
|
||||
void removeTagsAction();
|
||||
void createTagsAction();
|
||||
void deleteTagsAction();
|
||||
|
|
|
@ -54,7 +54,7 @@
|
|||
#include "base/utils/version.h"
|
||||
#include "api/isessionmanager.h"
|
||||
|
||||
inline const Utils::Version<3, 2> API_VERSION {2, 11, 3};
|
||||
inline const Utils::Version<3, 2> API_VERSION {2, 11, 4};
|
||||
|
||||
class QTimer;
|
||||
|
||||
|
@ -212,6 +212,7 @@ private:
|
|||
{{u"torrents"_s, u"setShareLimits"_s}, Http::METHOD_POST},
|
||||
{{u"torrents"_s, u"setSSLParameters"_s}, Http::METHOD_POST},
|
||||
{{u"torrents"_s, u"setSuperSeeding"_s}, Http::METHOD_POST},
|
||||
{{u"torrents"_s, u"setTags"_s}, Http::METHOD_POST},
|
||||
{{u"torrents"_s, u"setUploadLimit"_s}, Http::METHOD_POST},
|
||||
{{u"transfer"_s, u"setDownloadLimit"_s}, Http::METHOD_POST},
|
||||
{{u"transfer"_s, u"setSpeedLimitsMode"_s}, Http::METHOD_POST},
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue