mirror of
https://github.com/transmission/transmission.git
synced 2025-12-20 10:28:32 +00:00
perf: skip some excess announce list rebuilds
This commit is contained in:
@@ -92,6 +92,16 @@ public:
|
|||||||
|
|
||||||
[[nodiscard]] tr_tracker_tier_t nextTier() const;
|
[[nodiscard]] tr_tracker_tier_t nextTier() const;
|
||||||
|
|
||||||
|
[[nodiscard]] bool operator==(tr_announce_list const& that) const
|
||||||
|
{
|
||||||
|
return trackers_ == that.trackers_;
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] bool operator!=(tr_announce_list const& that) const
|
||||||
|
{
|
||||||
|
return trackers_ != that.trackers_;
|
||||||
|
}
|
||||||
|
|
||||||
bool add(std::string_view announce_url_sv)
|
bool add(std::string_view announce_url_sv)
|
||||||
{
|
{
|
||||||
return add(announce_url_sv, this->nextTier());
|
return add(announce_url_sv, this->nextTier());
|
||||||
|
|||||||
@@ -581,8 +581,8 @@ private:
|
|||||||
{
|
{
|
||||||
auto announce_list = tor->announceList();
|
auto announce_list = tor->announceList();
|
||||||
|
|
||||||
// if it's a public torrent, inject the default trackers
|
// if it's a public torrent, add the default trackers
|
||||||
if (!tor->isPrivate())
|
if (tor->isPublic())
|
||||||
{
|
{
|
||||||
announce_list.add(tor->session->defaultTrackers());
|
announce_list.add(tor->session->defaultTrackers());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2253,8 +2253,22 @@ int tr_sessionGetCacheLimit_MB(tr_session const* session)
|
|||||||
|
|
||||||
void tr_session::setDefaultTrackers(std::string_view trackers)
|
void tr_session::setDefaultTrackers(std::string_view trackers)
|
||||||
{
|
{
|
||||||
this->default_trackers_str_ = trackers;
|
auto const oldval = default_trackers_;
|
||||||
this->default_trackers_.parse(trackers);
|
|
||||||
|
default_trackers_str_ = trackers;
|
||||||
|
default_trackers_.parse(trackers);
|
||||||
|
|
||||||
|
// if the list changed, update all the public torrents
|
||||||
|
if (default_trackers_ != oldval)
|
||||||
|
{
|
||||||
|
for (auto* tor : torrents)
|
||||||
|
{
|
||||||
|
if (tor->isPublic())
|
||||||
|
{
|
||||||
|
tr_announcerResetTorrent(announcer, tor);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void tr_sessionSetDefaultTrackers(tr_session* session, char const* trackers)
|
void tr_sessionSetDefaultTrackers(tr_session* session, char const* trackers)
|
||||||
|
|||||||
@@ -1195,7 +1195,7 @@ char* tr_torrentGetMagnetLink(tr_torrent const* tor);
|
|||||||
* along with tr_torrentSetTrackerList(), is intended for import/export
|
* along with tr_torrentSetTrackerList(), is intended for import/export
|
||||||
* and user editing. It does *not* include the "default trackers" that
|
* and user editing. It does *not* include the "default trackers" that
|
||||||
* are applied to all public torrents. If you want a full display of all
|
* are applied to all public torrents. If you want a full display of all
|
||||||
* trackers, use tr_torrentTracker() and tr_torrentTackerCount()
|
* trackers, use tr_torrentTracker() and tr_torrentTrackerCount()
|
||||||
*/
|
*/
|
||||||
char* tr_torrentGetTrackerList(tr_torrent const* tor);
|
char* tr_torrentGetTrackerList(tr_torrent const* tor);
|
||||||
|
|
||||||
|
|||||||
@@ -25,6 +25,7 @@
|
|||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
#include <QLineEdit>
|
#include <QLineEdit>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
|
#include <QPlainTextEdit>
|
||||||
#include <QPushButton>
|
#include <QPushButton>
|
||||||
#include <QSpinBox>
|
#include <QSpinBox>
|
||||||
#include <QStyle>
|
#include <QStyle>
|
||||||
@@ -239,12 +240,47 @@ void PrefsDialog::linkWidgetToPref(QWidget* widget, int pref_key)
|
|||||||
connect(spin_box, &QAbstractSpinBox::editingFinished, this, &PrefsDialog::spinBoxEditingFinished);
|
connect(spin_box, &QAbstractSpinBox::editingFinished, this, &PrefsDialog::spinBoxEditingFinished);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (auto const* edit = qobject_cast<QPlainTextEdit*>(widget); edit != nullptr)
|
static bool isDescendantOf(QObject const* descendant, QObject const* ancestor)
|
||||||
|
{
|
||||||
|
if (ancestor == nullptr)
|
||||||
{
|
{
|
||||||
connect(edit, &QPlainTextEdit::textChanged, this, &PrefsDialog::plainTextChanged);
|
return false;
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
while (descendant != nullptr)
|
||||||
|
{
|
||||||
|
if (descendant == ancestor)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
descendant = descendant->parent();
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void PrefsDialog::focusChanged(QWidget* old, QWidget* cur)
|
||||||
|
{
|
||||||
|
// We don't want to change the preference every time there's a keystroke
|
||||||
|
// in a QPlainTextEdit, so instead of connecting to the textChanged signal,
|
||||||
|
// only update the pref when the text changed AND focus was lost.
|
||||||
|
char const constexpr* const StartValue = "StartValue";
|
||||||
|
|
||||||
|
if (auto* const edit = qobject_cast<QPlainTextEdit*>(cur); isDescendantOf(edit, this))
|
||||||
|
{
|
||||||
|
edit->setProperty(StartValue, edit->toPlainText());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (auto const* const edit = qobject_cast<QPlainTextEdit*>(old); isDescendantOf(edit, this))
|
||||||
|
{
|
||||||
|
if (auto const val = edit->toPlainText(); val != edit->property(StartValue).toString())
|
||||||
|
{
|
||||||
|
setPref(PreferenceWidget{ old }.getPrefKey(), val);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// (TODO: we probably want to do this for single-line text entries too?)
|
||||||
}
|
}
|
||||||
|
|
||||||
void PrefsDialog::checkBoxToggled(bool checked)
|
void PrefsDialog::checkBoxToggled(bool checked)
|
||||||
@@ -306,22 +342,6 @@ void PrefsDialog::pathChanged(QString const& path)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void PrefsDialog::plainTextChanged()
|
|
||||||
{
|
|
||||||
PreferenceWidget const pref_widget(sender());
|
|
||||||
|
|
||||||
if (pref_widget.is<QPlainTextEdit>())
|
|
||||||
{
|
|
||||||
auto const* const plain_text_edit = pref_widget.as<QPlainTextEdit>();
|
|
||||||
|
|
||||||
if (plain_text_edit->document()->isModified())
|
|
||||||
{
|
|
||||||
prefs_.set(pref_widget.getPrefKey(), plain_text_edit->toPlainText());
|
|
||||||
// we avoid using setPref() because the included refreshPref() call would reset the cursor while we're editing
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/***
|
/***
|
||||||
****
|
****
|
||||||
***/
|
***/
|
||||||
@@ -704,6 +724,8 @@ PrefsDialog::PrefsDialog(Session& session, Prefs& prefs, QWidget* parent)
|
|||||||
}
|
}
|
||||||
|
|
||||||
adjustSize();
|
adjustSize();
|
||||||
|
|
||||||
|
connect(qApp, &QApplication::focusChanged, this, &PrefsDialog::focusChanged);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PrefsDialog::setPref(int key, QVariant const& v)
|
void PrefsDialog::setPref(int key, QVariant const& v)
|
||||||
|
|||||||
@@ -29,12 +29,12 @@ public:
|
|||||||
PrefsDialog(Session&, Prefs&, QWidget* parent = nullptr);
|
PrefsDialog(Session&, Prefs&, QWidget* parent = nullptr);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
|
void focusChanged(QWidget* old, QWidget* now);
|
||||||
void checkBoxToggled(bool checked);
|
void checkBoxToggled(bool checked);
|
||||||
void spinBoxEditingFinished();
|
void spinBoxEditingFinished();
|
||||||
void timeEditingFinished();
|
void timeEditingFinished();
|
||||||
void lineEditingFinished();
|
void lineEditingFinished();
|
||||||
void pathChanged(QString const& path);
|
void pathChanged(QString const& path);
|
||||||
void plainTextChanged();
|
|
||||||
void refreshPref(int key);
|
void refreshPref(int key);
|
||||||
void encryptionEdited(int);
|
void encryptionEdited(int);
|
||||||
void altSpeedDaysEdited(int);
|
void altSpeedDaysEdited(int);
|
||||||
|
|||||||
Reference in New Issue
Block a user