perf(ui): fill the tables in a single repaint batch
A result page inserted its rows one setItem() at a time, so the viewport repainted per cell and, on the browse page, the row that became "current" fired the pacman queries behind the details panel in the middle of the fill. The fill now runs with updates disabled and the table's signals muted, released just before the row the user actually sees is selected. Generated with Codebuff 🤖 Co-Authored-By: Codebuff <noreply@codebuff.com>
This commit is contained in:
1 parent
52daeb6d30
commit
d789695333
1 file changed
+57
-11
+57
-11
@@ -39,6 +39,7 @@
|
|||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
// Worker threads
|
// Worker threads
|
||||||
SearchWorker::SearchWorker(const std::vector<IPackageManager*>& providers,
|
SearchWorker::SearchWorker(const std::vector<IPackageManager*>& providers,
|
||||||
@@ -206,6 +207,38 @@ static QString providersLabel(const PluginManager* pm, const PackageInfo& pkg) {
|
|||||||
return names.join(", ");
|
return names.join(", ");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Inserts rows into a table in one repaint batch, with the table's signals
|
||||||
|
// muted for the duration. Without it every setItem() repaints the viewport, and
|
||||||
|
// on the browse page each selection change fires the pacman queries behind the
|
||||||
|
// details panel — a thousand rows meant a thousand repaints and a pacman call
|
||||||
|
// in the middle of the fill.
|
||||||
|
class TableFillBatch {
|
||||||
|
public:
|
||||||
|
explicit TableFillBatch(QTableWidget* table) : m_table(table) {
|
||||||
|
if (!m_table) return;
|
||||||
|
m_table->setUpdatesEnabled(false);
|
||||||
|
m_blocker = std::make_unique<QSignalBlocker>(m_table);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Called before the caller selects a row: that selection is what refreshes
|
||||||
|
// the details panel, so it has to be seen by the table's signals. Idempotent,
|
||||||
|
// which lets the destructor cover an early return too.
|
||||||
|
void release() {
|
||||||
|
if (!m_table || !m_blocker) return;
|
||||||
|
m_blocker.reset();
|
||||||
|
m_table->setUpdatesEnabled(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
~TableFillBatch() { release(); }
|
||||||
|
|
||||||
|
TableFillBatch(const TableFillBatch&) = delete;
|
||||||
|
TableFillBatch& operator=(const TableFillBatch&) = delete;
|
||||||
|
|
||||||
|
private:
|
||||||
|
QTableWidget* m_table = nullptr;
|
||||||
|
std::unique_ptr<QSignalBlocker> m_blocker;
|
||||||
|
};
|
||||||
|
|
||||||
// Quote a CSV field when it contains the separator, a quote or a newline, so
|
// Quote a CSV field when it contains the separator, a quote or a newline, so
|
||||||
// exported lists stay importable in a spreadsheet.
|
// exported lists stay importable in a spreadsheet.
|
||||||
static QString csvField(const QString& value) {
|
static QString csvField(const QString& value) {
|
||||||
@@ -1640,11 +1673,14 @@ void MainWindow::onRecentActivityClicked(QListWidgetItem* item) {
|
|||||||
|
|
||||||
void MainWindow::populatePackageTable(const std::vector<PackageInfo>& results) {
|
void MainWindow::populatePackageTable(const std::vector<PackageInfo>& results) {
|
||||||
m_currentResults = results;
|
m_currentResults = results;
|
||||||
m_packageTable->setRowCount(0);
|
{
|
||||||
m_packageTable->setRowCount(static_cast<int>(results.size()));
|
TableFillBatch batch(m_packageTable);
|
||||||
|
m_packageTable->setRowCount(0);
|
||||||
|
m_packageTable->setRowCount(static_cast<int>(results.size()));
|
||||||
|
|
||||||
for (int i = 0; i < static_cast<int>(results.size()); ++i) {
|
for (int i = 0; i < static_cast<int>(results.size()); ++i) {
|
||||||
addPackageRow(i, results[i]);
|
addPackageRow(i, results[i]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
m_resultCount->setText(QString("%1 paquet(s)").arg(results.size()));
|
m_resultCount->setText(QString("%1 paquet(s)").arg(results.size()));
|
||||||
@@ -1675,10 +1711,13 @@ void MainWindow::populatePackageTable(const std::vector<PackageInfo>& results) {
|
|||||||
void MainWindow::appendPackageRows(const std::vector<PackageInfo>& results) {
|
void MainWindow::appendPackageRows(const std::vector<PackageInfo>& results) {
|
||||||
const int startRow = static_cast<int>(m_currentResults.size());
|
const int startRow = static_cast<int>(m_currentResults.size());
|
||||||
m_currentResults.insert(m_currentResults.end(), results.begin(), results.end());
|
m_currentResults.insert(m_currentResults.end(), results.begin(), results.end());
|
||||||
m_packageTable->setRowCount(static_cast<int>(m_currentResults.size()));
|
{
|
||||||
|
TableFillBatch batch(m_packageTable);
|
||||||
|
m_packageTable->setRowCount(static_cast<int>(m_currentResults.size()));
|
||||||
|
|
||||||
for (size_t i = 0; i < results.size(); ++i) {
|
for (size_t i = 0; i < results.size(); ++i) {
|
||||||
addPackageRow(startRow + static_cast<int>(i), results[i]);
|
addPackageRow(startRow + static_cast<int>(i), results[i]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
m_resultCount->setText(QString("%1 paquet(s)").arg(m_currentResults.size()));
|
m_resultCount->setText(QString("%1 paquet(s)").arg(m_currentResults.size()));
|
||||||
}
|
}
|
||||||
@@ -2031,12 +2070,14 @@ void MainWindow::onCleanupListFinished(std::vector<PackageInfo> results) {
|
|||||||
|
|
||||||
void MainWindow::populateCleanupTable(const std::vector<PackageInfo>& candidates) {
|
void MainWindow::populateCleanupTable(const std::vector<PackageInfo>& candidates) {
|
||||||
m_cleanupCandidates = candidates;
|
m_cleanupCandidates = candidates;
|
||||||
m_cleanupTable->setRowCount(0);
|
|
||||||
m_cleanupTable->setRowCount(static_cast<int>(candidates.size()));
|
|
||||||
|
|
||||||
QFont nameFont;
|
QFont nameFont;
|
||||||
nameFont.setWeight(QFont::DemiBold);
|
nameFont.setWeight(QFont::DemiBold);
|
||||||
|
|
||||||
|
TableFillBatch batch(m_cleanupTable);
|
||||||
|
m_cleanupTable->setRowCount(0);
|
||||||
|
m_cleanupTable->setRowCount(static_cast<int>(candidates.size()));
|
||||||
|
|
||||||
int orphans = 0;
|
int orphans = 0;
|
||||||
for (int i = 0; i < static_cast<int>(candidates.size()); ++i) {
|
for (int i = 0; i < static_cast<int>(candidates.size()); ++i) {
|
||||||
const PackageInfo& pkg = candidates[i];
|
const PackageInfo& pkg = candidates[i];
|
||||||
@@ -2058,6 +2099,7 @@ void MainWindow::populateCleanupTable(const std::vector<PackageInfo>& candidates
|
|||||||
m_cleanupTable->setItem(i, 3,
|
m_cleanupTable->setItem(i, 3,
|
||||||
new QTableWidgetItem(providersLabel(m_pluginManager, pkg)));
|
new QTableWidgetItem(providersLabel(m_pluginManager, pkg)));
|
||||||
}
|
}
|
||||||
|
batch.release();
|
||||||
|
|
||||||
m_cleanupCount->setText(QString("%1 orphelin(s) · %2 legacy")
|
m_cleanupCount->setText(QString("%1 orphelin(s) · %2 legacy")
|
||||||
.arg(orphans).arg(static_cast<int>(candidates.size()) - orphans));
|
.arg(orphans).arg(static_cast<int>(candidates.size()) - orphans));
|
||||||
@@ -2411,6 +2453,7 @@ void MainWindow::refreshHistoryTable() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
m_historyCount->setText(QString("%1 action(s)").arg(entries.size()));
|
m_historyCount->setText(QString("%1 action(s)").arg(entries.size()));
|
||||||
|
TableFillBatch batch(m_historyTable);
|
||||||
m_historyTable->setRowCount(static_cast<int>(entries.size()));
|
m_historyTable->setRowCount(static_cast<int>(entries.size()));
|
||||||
|
|
||||||
for (int i = 0; i < static_cast<int>(entries.size()); ++i) {
|
for (int i = 0; i < static_cast<int>(entries.size()); ++i) {
|
||||||
@@ -2740,12 +2783,14 @@ void MainWindow::onRescanPlugins() {
|
|||||||
|
|
||||||
void MainWindow::refreshPluginsTable() {
|
void MainWindow::refreshPluginsTable() {
|
||||||
const auto& plugins = m_pluginManager->plugins();
|
const auto& plugins = m_pluginManager->plugins();
|
||||||
m_pluginTable->setRowCount(0);
|
|
||||||
m_pluginTable->setRowCount(static_cast<int>(plugins.size()));
|
|
||||||
|
|
||||||
QFont nameFont;
|
QFont nameFont;
|
||||||
nameFont.setWeight(QFont::DemiBold);
|
nameFont.setWeight(QFont::DemiBold);
|
||||||
|
|
||||||
|
TableFillBatch batch(m_pluginTable);
|
||||||
|
m_pluginTable->setRowCount(0);
|
||||||
|
m_pluginTable->setRowCount(static_cast<int>(plugins.size()));
|
||||||
|
|
||||||
for (int i = 0; i < static_cast<int>(plugins.size()); ++i) {
|
for (int i = 0; i < static_cast<int>(plugins.size()); ++i) {
|
||||||
const auto& entry = plugins[i];
|
const auto& entry = plugins[i];
|
||||||
|
|
||||||
@@ -2789,6 +2834,7 @@ void MainWindow::refreshPluginsTable() {
|
|||||||
: "alert"));
|
: "alert"));
|
||||||
m_pluginTable->setItem(i, 4, statusItem);
|
m_pluginTable->setItem(i, 4, statusItem);
|
||||||
}
|
}
|
||||||
|
batch.release();
|
||||||
|
|
||||||
if (!plugins.empty()) {
|
if (!plugins.empty()) {
|
||||||
// Keep the previously selected plugin selected when possible.
|
// Keep the previously selected plugin selected when possible.
|
||||||
|
|||||||
Reference in new issue
Block a user