mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-11-22 03:00:46 +03:00
A few more small speedups
This commit is contained in:
parent
22c5076c64
commit
4357c47ebe
8 changed files with 103 additions and 120 deletions
|
@ -197,14 +197,7 @@ compactDatabase(lmdb::env &from, lmdb::env &to)
|
||||||
toTxn.commit();
|
toTxn.commit();
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class T>
|
static bool
|
||||||
bool
|
|
||||||
containsStateUpdates(const T &e)
|
|
||||||
{
|
|
||||||
return std::visit([](const auto &ev) { return Cache::isStateEvent_<decltype(ev)>; }, e);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool
|
|
||||||
containsStateUpdates(const mtx::events::collections::StrippedEvents &e)
|
containsStateUpdates(const mtx::events::collections::StrippedEvents &e)
|
||||||
{
|
{
|
||||||
using namespace mtx::events;
|
using namespace mtx::events;
|
||||||
|
@ -1996,54 +1989,6 @@ Cache::updateState(const std::string &room, const mtx::responses::StateEvents &s
|
||||||
txn.commit();
|
txn.commit();
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace {
|
|
||||||
template<typename T>
|
|
||||||
auto
|
|
||||||
isMessage(const mtx::events::RoomEvent<T> &e)
|
|
||||||
-> std::enable_if_t<std::is_same<decltype(e.content.msgtype), std::string>::value, bool>
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
auto
|
|
||||||
isMessage(const mtx::events::Event<T> &)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
auto
|
|
||||||
isMessage(const mtx::events::EncryptedEvent<T> &)
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto
|
|
||||||
isMessage(const mtx::events::RoomEvent<mtx::events::voip::CallInvite> &)
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto
|
|
||||||
isMessage(const mtx::events::RoomEvent<mtx::events::voip::CallAnswer> &)
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto
|
|
||||||
isMessage(const mtx::events::RoomEvent<mtx::events::voip::CallHangUp> &)
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// auto
|
|
||||||
// isMessage(const mtx::events::RoomEvent<mtx::events::voip::CallReject> &)
|
|
||||||
// {
|
|
||||||
// return true;
|
|
||||||
// }
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
std::optional<mtx::events::StateEvent<T>>
|
std::optional<mtx::events::StateEvent<T>>
|
||||||
Cache::getStateEvent(lmdb::txn &txn, const std::string &room_id, std::string_view state_key)
|
Cache::getStateEvent(lmdb::txn &txn, const std::string &room_id, std::string_view state_key)
|
||||||
|
@ -2418,10 +2363,9 @@ Cache::saveState(const mtx::responses::Sync &res)
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const auto &e : room.second.timeline.events) {
|
for (const auto &e : room.second.timeline.events) {
|
||||||
if (!std::visit([](const auto &e) -> bool { return isMessage(e); }, e))
|
if (!mtx::accessors::is_message(e))
|
||||||
continue;
|
continue;
|
||||||
updatedInfo.approximate_last_modification_ts =
|
updatedInfo.approximate_last_modification_ts = mtx::accessors::origin_server_ts_ms(e);
|
||||||
std::visit([](const auto &e) -> uint64_t { return e.origin_server_ts; }, e);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (auto newRoomInfoDump = nlohmann::json(updatedInfo).dump();
|
if (auto newRoomInfoDump = nlohmann::json(updatedInfo).dump();
|
||||||
|
@ -2592,14 +2536,14 @@ Cache::roomsWithStateUpdates(const mtx::responses::Sync &res)
|
||||||
for (const auto &room : res.rooms.join) {
|
for (const auto &room : res.rooms.join) {
|
||||||
bool hasUpdates = false;
|
bool hasUpdates = false;
|
||||||
for (const auto &s : room.second.state.events) {
|
for (const auto &s : room.second.state.events) {
|
||||||
if (containsStateUpdates(s)) {
|
if (mtx::accessors::is_state_event(s)) {
|
||||||
hasUpdates = true;
|
hasUpdates = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const auto &s : room.second.timeline.events) {
|
for (const auto &s : room.second.timeline.events) {
|
||||||
if (containsStateUpdates(s)) {
|
if (mtx::accessors::is_state_event(s)) {
|
||||||
hasUpdates = true;
|
hasUpdates = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
struct IsStateEvent
|
struct IsStateEvent
|
||||||
{
|
{
|
||||||
template<class T>
|
template<class T>
|
||||||
|
@ -38,6 +39,15 @@ struct EventMsgType
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct EventType
|
||||||
|
{
|
||||||
|
template<class T>
|
||||||
|
mtx::events::EventType operator()(const mtx::events::Event<T> &e)
|
||||||
|
{
|
||||||
|
return e.type;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
struct CallType
|
struct CallType
|
||||||
{
|
{
|
||||||
template<class T>
|
template<class T>
|
||||||
|
@ -313,8 +323,13 @@ mtx::accessors::sender(const mtx::events::collections::TimelineEvents &event)
|
||||||
QDateTime
|
QDateTime
|
||||||
mtx::accessors::origin_server_ts(const mtx::events::collections::TimelineEvents &event)
|
mtx::accessors::origin_server_ts(const mtx::events::collections::TimelineEvents &event)
|
||||||
{
|
{
|
||||||
return QDateTime::fromMSecsSinceEpoch(
|
return QDateTime::fromMSecsSinceEpoch(origin_server_ts_ms(event));
|
||||||
std::visit([](const auto &e) { return e.origin_server_ts; }, event));
|
}
|
||||||
|
|
||||||
|
std::uint64_t
|
||||||
|
mtx::accessors::origin_server_ts_ms(const mtx::events::collections::TimelineEvents &event)
|
||||||
|
{
|
||||||
|
return std::visit([](const auto &e) { return e.origin_server_ts; }, event);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string
|
std::string
|
||||||
|
@ -323,6 +338,11 @@ mtx::accessors::filename(const mtx::events::collections::TimelineEvents &event)
|
||||||
return std::visit(EventFilename{}, event);
|
return std::visit(EventFilename{}, event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mtx::events::EventType
|
||||||
|
mtx::accessors::event_type(const mtx::events::collections::TimelineEvents &event)
|
||||||
|
{
|
||||||
|
return std::visit(EventType{}, event);
|
||||||
|
}
|
||||||
mtx::events::MessageType
|
mtx::events::MessageType
|
||||||
mtx::accessors::msg_type(const mtx::events::collections::TimelineEvents &event)
|
mtx::accessors::msg_type(const mtx::events::collections::TimelineEvents &event)
|
||||||
{
|
{
|
||||||
|
@ -463,8 +483,70 @@ mtx::accessors::serialize_event(const mtx::events::collections::TimelineEvents &
|
||||||
return nlohmann::json(event);
|
return nlohmann::json(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
mtx::accessors::is_state_event(const mtx::events::collections::StateEvents &event)
|
||||||
|
{
|
||||||
|
return std::visit(IsStateEvent{}, event);
|
||||||
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
mtx::accessors::is_state_event(const mtx::events::collections::TimelineEvents &event)
|
mtx::accessors::is_state_event(const mtx::events::collections::TimelineEvents &event)
|
||||||
{
|
{
|
||||||
return std::visit(IsStateEvent{}, event);
|
return std::visit(IsStateEvent{}, event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
static constexpr auto
|
||||||
|
isMessage(const mtx::events::RoomEvent<T> &e)
|
||||||
|
-> std::enable_if_t<std::is_same<decltype(e.content.msgtype), std::string>::value, bool>
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
static constexpr auto
|
||||||
|
isMessage(const mtx::events::Event<T> &)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
static constexpr auto
|
||||||
|
isMessage(const mtx::events::EncryptedEvent<T> &)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
static constexpr auto
|
||||||
|
isMessage(const mtx::events::RoomEvent<mtx::events::voip::CallInvite> &)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
static constexpr auto
|
||||||
|
isMessage(const mtx::events::RoomEvent<mtx::events::voip::CallAnswer> &)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
static constexpr auto
|
||||||
|
isMessage(const mtx::events::RoomEvent<mtx::events::voip::CallHangUp> &)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
static constexpr auto
|
||||||
|
isMessage(const mtx::events::RoomEvent<mtx::events::voip::CallReject> &)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
static constexpr auto
|
||||||
|
isMessage(const mtx::events::RoomEvent<mtx::events::voip::CallSelectAnswer> &)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
mtx::accessors::is_message(const mtx::events::collections::TimelineEvents &event)
|
||||||
|
{
|
||||||
|
return std::visit([](const auto &e) { return isMessage(e); }, event);
|
||||||
|
}
|
||||||
|
|
|
@ -47,17 +47,26 @@ room_id(const mtx::events::collections::TimelineEvents &event);
|
||||||
const std::string &
|
const std::string &
|
||||||
sender(const mtx::events::collections::TimelineEvents &event);
|
sender(const mtx::events::collections::TimelineEvents &event);
|
||||||
|
|
||||||
|
bool
|
||||||
|
is_state_event(const mtx::events::collections::StateEvents &event);
|
||||||
bool
|
bool
|
||||||
is_state_event(const mtx::events::collections::TimelineEvents &event);
|
is_state_event(const mtx::events::collections::TimelineEvents &event);
|
||||||
|
|
||||||
QDateTime
|
QDateTime
|
||||||
origin_server_ts(const mtx::events::collections::TimelineEvents &event);
|
origin_server_ts(const mtx::events::collections::TimelineEvents &event);
|
||||||
|
|
||||||
|
std::uint64_t
|
||||||
|
origin_server_ts_ms(const mtx::events::collections::TimelineEvents &event);
|
||||||
|
|
||||||
std::string
|
std::string
|
||||||
filename(const mtx::events::collections::TimelineEvents &event);
|
filename(const mtx::events::collections::TimelineEvents &event);
|
||||||
|
|
||||||
|
mtx::events::EventType
|
||||||
|
event_type(const mtx::events::collections::TimelineEvents &event);
|
||||||
mtx::events::MessageType
|
mtx::events::MessageType
|
||||||
msg_type(const mtx::events::collections::TimelineEvents &event);
|
msg_type(const mtx::events::collections::TimelineEvents &event);
|
||||||
|
bool
|
||||||
|
is_message(const mtx::events::collections::TimelineEvents &event);
|
||||||
std::string
|
std::string
|
||||||
room_name(const mtx::events::collections::TimelineEvents &event);
|
room_name(const mtx::events::collections::TimelineEvents &event);
|
||||||
std::string
|
std::string
|
||||||
|
|
|
@ -6,8 +6,6 @@
|
||||||
|
|
||||||
#include <mtxclient/http/client.hpp>
|
#include <mtxclient/http/client.hpp>
|
||||||
|
|
||||||
#include "Logging.h"
|
|
||||||
|
|
||||||
namespace http {
|
namespace http {
|
||||||
mtx::http::Client *
|
mtx::http::Client *
|
||||||
client();
|
client();
|
||||||
|
|
|
@ -509,8 +509,7 @@ EventStore::handleSync(const mtx::responses::Timeline &events)
|
||||||
std::get_if<mtx::events::EncryptedEvent<mtx::events::msg::Encrypted>>(&event)) {
|
std::get_if<mtx::events::EncryptedEvent<mtx::events::msg::Encrypted>>(&event)) {
|
||||||
auto d_event = decryptEvent({room_id_, encrypted->event_id}, *encrypted);
|
auto d_event = decryptEvent({room_id_, encrypted->event_id}, *encrypted);
|
||||||
if (d_event->event &&
|
if (d_event->event &&
|
||||||
std::visit([](auto e) { return (e.sender != utils::localUser().toStdString()); },
|
mtx::accessors::sender(*d_event->event) != utils::localUser().toStdString()) {
|
||||||
*d_event->event)) {
|
|
||||||
handle_room_verification(this, *d_event->event);
|
handle_room_verification(this, *d_event->event);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -260,8 +260,7 @@ toRoomEventType(const mtx::events::collections::TimelineEvents &event)
|
||||||
QString
|
QString
|
||||||
toRoomEventTypeString(const mtx::events::collections::TimelineEvents &event)
|
toRoomEventTypeString(const mtx::events::collections::TimelineEvents &event)
|
||||||
{
|
{
|
||||||
return std::visit([](const auto &e) { return QString::fromStdString(to_string(e.type)); },
|
return QString::fromStdString(to_string(mtx::accessors::event_type(event)));
|
||||||
event);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
mtx::events::EventType
|
mtx::events::EventType
|
||||||
|
@ -1271,56 +1270,6 @@ TimelineModel::addEvents(const mtx::responses::Timeline &timeline)
|
||||||
updateLastMessage();
|
updateLastMessage();
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
static constexpr auto
|
|
||||||
isMessage(const mtx::events::RoomEvent<T> &e)
|
|
||||||
-> std::enable_if_t<std::is_same<decltype(e.content.msgtype), std::string>::value, bool>
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
static constexpr auto
|
|
||||||
isMessage(const mtx::events::Event<T> &)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
static constexpr auto
|
|
||||||
isMessage(const mtx::events::EncryptedEvent<T> &)
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
static constexpr auto
|
|
||||||
isMessage(const mtx::events::RoomEvent<mtx::events::voip::CallInvite> &)
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
static constexpr auto
|
|
||||||
isMessage(const mtx::events::RoomEvent<mtx::events::voip::CallAnswer> &)
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
static constexpr auto
|
|
||||||
isMessage(const mtx::events::RoomEvent<mtx::events::voip::CallHangUp> &)
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
static constexpr auto
|
|
||||||
isMessage(const mtx::events::RoomEvent<mtx::events::voip::CallReject> &)
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
static constexpr auto
|
|
||||||
isMessage(const mtx::events::RoomEvent<mtx::events::voip::CallSelectAnswer> &)
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Workaround. We also want to see a room at the top, if we just joined it
|
// Workaround. We also want to see a room at the top, if we just joined it
|
||||||
auto
|
auto
|
||||||
isYourJoin(const mtx::events::StateEvent<mtx::events::state::Member> &e, EventStore &events)
|
isYourJoin(const mtx::events::StateEvent<mtx::events::state::Member> &e, EventStore &events)
|
||||||
|
@ -1385,7 +1334,7 @@ TimelineModel::updateLastMessage()
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!std::visit([](const auto &e) -> bool { return isMessage(e); }, *event))
|
if (!mtx::accessors::is_message(*event))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
auto description = utils::getMessageDescription(
|
auto description = utils::getMessageDescription(
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
#include "EventExpiry.h"
|
#include "EventExpiry.h"
|
||||||
|
|
||||||
#include "Cache_p.h"
|
#include "Cache_p.h"
|
||||||
|
#include "Logging.h"
|
||||||
#include "MainWindow.h"
|
#include "MainWindow.h"
|
||||||
#include "MatrixClient.h"
|
#include "MatrixClient.h"
|
||||||
#include "timeline/TimelineModel.h"
|
#include "timeline/TimelineModel.h"
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
#include "HiddenEvents.h"
|
#include "HiddenEvents.h"
|
||||||
|
|
||||||
#include "Cache_p.h"
|
#include "Cache_p.h"
|
||||||
|
#include "Logging.h"
|
||||||
#include "MainWindow.h"
|
#include "MainWindow.h"
|
||||||
#include "MatrixClient.h"
|
#include "MatrixClient.h"
|
||||||
#include "timeline/TimelineModel.h"
|
#include "timeline/TimelineModel.h"
|
||||||
|
|
Loading…
Reference in a new issue