mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-11-22 11:00:48 +03:00
Optimize user model construction by 2.5x
This commit is contained in:
parent
8c06460e91
commit
ee5b33978a
3 changed files with 20 additions and 10 deletions
|
@ -3196,8 +3196,11 @@ Cache::getMembers(const std::string &room_id, std::size_t startIndex, std::size_
|
||||||
|
|
||||||
try {
|
try {
|
||||||
MemberInfo tmp = nlohmann::json::parse(user_data).get<MemberInfo>();
|
MemberInfo tmp = nlohmann::json::parse(user_data).get<MemberInfo>();
|
||||||
members.emplace_back(RoomMember{QString::fromStdString(std::string(user_id)),
|
members.emplace_back(RoomMember{
|
||||||
QString::fromStdString(tmp.name)});
|
QString::fromStdString(std::string(user_id)),
|
||||||
|
QString::fromStdString(tmp.name),
|
||||||
|
QString::fromStdString(tmp.avatar_url),
|
||||||
|
});
|
||||||
} catch (const nlohmann::json::exception &e) {
|
} catch (const nlohmann::json::exception &e) {
|
||||||
nhlog::db()->warn("{}", e.what());
|
nhlog::db()->warn("{}", e.what());
|
||||||
}
|
}
|
||||||
|
@ -3263,9 +3266,12 @@ Cache::getMembersFromInvite(const std::string &room_id, std::size_t startIndex,
|
||||||
|
|
||||||
try {
|
try {
|
||||||
MemberInfo tmp = nlohmann::json::parse(user_data).get<MemberInfo>();
|
MemberInfo tmp = nlohmann::json::parse(user_data).get<MemberInfo>();
|
||||||
members.emplace_back(RoomMember{QString::fromStdString(std::string(user_id)),
|
members.emplace_back(RoomMember{
|
||||||
QString::fromStdString(tmp.name),
|
QString::fromStdString(std::string(user_id)),
|
||||||
tmp.is_direct});
|
QString::fromStdString(tmp.name),
|
||||||
|
QString::fromStdString(tmp.avatar_url),
|
||||||
|
tmp.is_direct,
|
||||||
|
});
|
||||||
} catch (const nlohmann::json::exception &e) {
|
} catch (const nlohmann::json::exception &e) {
|
||||||
nhlog::db()->warn("{}", e.what());
|
nhlog::db()->warn("{}", e.what());
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,6 +28,7 @@ struct RoomMember
|
||||||
{
|
{
|
||||||
QString user_id;
|
QString user_id;
|
||||||
QString display_name;
|
QString display_name;
|
||||||
|
QString avatar_url;
|
||||||
bool is_direct = false;
|
bool is_direct = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -34,12 +34,15 @@ UsersModel::UsersModel(const std::string &roomId, QObject *parent)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for (const auto &m : cache::roomMembers(roomId)) {
|
const auto start_at = std::chrono::steady_clock::now();
|
||||||
displayNames.push_back(QString::fromStdString(cache::displayName(room_id, m)));
|
for (const auto &m : cache::getMembers(roomId, 0, -1)) {
|
||||||
userids.push_back(QString::fromStdString(m));
|
displayNames.push_back(m.display_name);
|
||||||
avatarUrls.push_back(
|
userids.push_back(m.user_id);
|
||||||
cache::avatarUrl(QString::fromStdString(room_id), QString::fromStdString(m)));
|
avatarUrls.push_back(m.avatar_url);
|
||||||
}
|
}
|
||||||
|
const auto end_at = std::chrono::steady_clock::now();
|
||||||
|
const auto build_time = std::chrono::duration<double, std::milli>(end_at - start_at);
|
||||||
|
nhlog::ui()->debug("UsersModel: build data: {} ms", build_time.count());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue