mirror of
https://github.com/Mahdi-zarei/nekoray.git
synced 2025-12-19 05:30:06 +08:00
improve handling massive amount of profiles
This commit is contained in:
parent
43252d9bac
commit
27532ddaec
@ -41,39 +41,8 @@ public:
|
||||
return;
|
||||
}
|
||||
|
||||
// 纠错: order 里面含有不在当前表格控件的 id
|
||||
bool needSave = false;
|
||||
auto deleted_profiles = order;
|
||||
for (int i = 0; i < this->rowCount(); i++) {
|
||||
auto id = row2Id[i];
|
||||
deleted_profiles.removeAll(id);
|
||||
}
|
||||
for (auto deleted_profile: deleted_profiles) {
|
||||
needSave = true;
|
||||
order.removeAll(deleted_profile);
|
||||
}
|
||||
|
||||
// map(dstRow -> srcId)
|
||||
QMap<int, int> newRows;
|
||||
for (int i = 0; i < this->rowCount(); i++) {
|
||||
auto id = row2Id[i];
|
||||
auto dst = order.indexOf(id);
|
||||
if (dst == i) continue;
|
||||
if (dst == -1) {
|
||||
// 纠错: 新的profile不需要移动
|
||||
needSave = true;
|
||||
continue;
|
||||
}
|
||||
newRows[dst] = id;
|
||||
}
|
||||
|
||||
for (int i = 0; i < this->rowCount(); i++) {
|
||||
if (!newRows.contains(i)) continue;
|
||||
row2Id[i] = newRows[i];
|
||||
}
|
||||
|
||||
// Then save the order
|
||||
_save_order(needSave || saveToFile);
|
||||
_save_order(saveToFile);
|
||||
};
|
||||
|
||||
protected:
|
||||
|
||||
@ -768,7 +768,6 @@ namespace NekoGui_sub {
|
||||
}
|
||||
}
|
||||
|
||||
// 解析并添加 profile
|
||||
rawUpdater->update(content);
|
||||
|
||||
if (group != nullptr) {
|
||||
@ -790,13 +789,26 @@ namespace NekoGui_sub {
|
||||
|
||||
QString notice_added;
|
||||
QString notice_deleted;
|
||||
for (const auto &ent: only_out) {
|
||||
notice_added += "[+] " + ent->bean->DisplayTypeAndName() + "\n";
|
||||
if (only_out.size() < 1000)
|
||||
{
|
||||
for (const auto &ent: only_out) {
|
||||
notice_added += "[+] " + ent->bean->DisplayTypeAndName() + "\n";
|
||||
}
|
||||
} else
|
||||
{
|
||||
notice_added += QString("[+] ") + "added " + Int2String(only_out.size()) + "\n";
|
||||
}
|
||||
for (const auto &ent: only_in) {
|
||||
notice_deleted += "[-] " + ent->bean->DisplayTypeAndName() + "\n";
|
||||
if (only_in.size() < 1000)
|
||||
{
|
||||
for (const auto &ent: only_in) {
|
||||
notice_deleted += "[-] " + ent->bean->DisplayTypeAndName() + "\n";
|
||||
}
|
||||
} else
|
||||
{
|
||||
notice_deleted += QString("[-] ") + "deleted " + Int2String(only_in.size()) + "\n";
|
||||
}
|
||||
|
||||
|
||||
// sort according to order in remote
|
||||
group->order = {};
|
||||
for (const auto &ent: rawUpdater->updated_order) {
|
||||
|
||||
@ -63,7 +63,10 @@ void UI_InitMainWindow() {
|
||||
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) {
|
||||
mainwindow = this;
|
||||
MW_dialog_message = [=](const QString &a, const QString &b) {
|
||||
runOnUiThread([=] { dialog_message_impl(a, b); });
|
||||
runOnUiThread([=]
|
||||
{
|
||||
dialog_message_impl(a, b);
|
||||
});
|
||||
};
|
||||
|
||||
// Load Manager
|
||||
@ -1275,23 +1278,9 @@ void MainWindow::refresh_proxy_list(const int &id) {
|
||||
|
||||
void MainWindow::refresh_proxy_list_impl(const int &id, GroupSortAction groupSortAction) {
|
||||
ui->proxyListTable->setUpdatesEnabled(false);
|
||||
// id < 0 重绘
|
||||
if (id < 0) {
|
||||
// 清空数据
|
||||
ui->proxyListTable->row2Id.clear();
|
||||
ui->proxyListTable->setRowCount(0);
|
||||
// 添加行
|
||||
int row = -1;
|
||||
auto profiles = NekoGui::profileManager->GetGroup(NekoGui::dataStore->current_group)->Profiles();
|
||||
for (const auto& ent: profiles) {
|
||||
row++;
|
||||
ui->proxyListTable->insertRow(row);
|
||||
ui->proxyListTable->row2Id += ent->id;
|
||||
}
|
||||
}
|
||||
|
||||
// 显示排序
|
||||
if (id < 0) {
|
||||
switch (groupSortAction.method) {
|
||||
case GroupSortMethod::Raw: {
|
||||
auto group = NekoGui::profileManager->CurrentGroup();
|
||||
@ -1359,6 +1348,18 @@ void MainWindow::refresh_proxy_list_impl(const int &id, GroupSortAction groupSor
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (ui->proxyListTable->order.empty())
|
||||
{
|
||||
auto profiles = NekoGui::profileManager->GetGroup(NekoGui::dataStore->current_group)->Profiles();
|
||||
for (const auto& ent: profiles) {
|
||||
ui->proxyListTable->row2Id += ent->id;
|
||||
}
|
||||
ui->proxyListTable->setRowCount(profiles.size());
|
||||
} else
|
||||
{
|
||||
ui->proxyListTable->row2Id << ui->proxyListTable->order;
|
||||
ui->proxyListTable->setRowCount(ui->proxyListTable->order.size());
|
||||
}
|
||||
ui->proxyListTable->update_order(groupSortAction.save_sort);
|
||||
}
|
||||
|
||||
@ -1381,11 +1382,13 @@ void MainWindow::refresh_proxy_list_impl_refresh_data(const int &id, bool stoppi
|
||||
refresh_table_item(rowID, profile, stopping);
|
||||
} else
|
||||
{
|
||||
ui->proxyListTable->blockSignals(true);
|
||||
for (int row = 0; row < ui->proxyListTable->rowCount(); row++) {
|
||||
auto profileId = ui->proxyListTable->row2Id[row];
|
||||
auto profile = NekoGui::profileManager->GetProfile(profileId);
|
||||
refresh_table_item(row, profile, stopping);
|
||||
}
|
||||
ui->proxyListTable->blockSignals(false);
|
||||
}
|
||||
ui->proxyListTable->setUpdatesEnabled(true);
|
||||
}
|
||||
@ -1947,6 +1950,11 @@ inline void FastAppendTextDocument(const QString &message, QTextDocument *doc) {
|
||||
}
|
||||
|
||||
void MainWindow::show_log_impl(const QString &log) {
|
||||
if (log.size() > 20000)
|
||||
{
|
||||
show_log_impl("Ignored massive log of size:" + Int2String(log.size()));
|
||||
return;
|
||||
}
|
||||
auto lines = SplitLines(log.trimmed());
|
||||
if (lines.isEmpty()) return;
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user