From 17f74130a93d5b5eb9fb33e453670e7247494104 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Fri, 9 Dec 2022 23:43:12 +0100 Subject: Matrix: continue from cache instead of initial sync everytime. Mainly improves pantalaimon sync speed --- plugins/Matrix.hpp | 20 +++----------------- plugins/utils/UniqueProcess.hpp | 7 +++++++ 2 files changed, 10 insertions(+), 17 deletions(-) create mode 100644 plugins/utils/UniqueProcess.hpp (limited to 'plugins') diff --git a/plugins/Matrix.hpp b/plugins/Matrix.hpp index c1ee3bd..aae7411 100644 --- a/plugins/Matrix.hpp +++ b/plugins/Matrix.hpp @@ -326,8 +326,6 @@ namespace QuickMedia { virtual void remove_user(MatrixEventUserInfo user_info) = 0; virtual void set_user_info(MatrixEventUserInfo user_info) = 0; virtual void set_room_info(MatrixEventRoomInfo room_info) = 0; - - virtual void clear_data() = 0; }; class Matrix; @@ -362,8 +360,6 @@ namespace QuickMedia { void set_room_as_read(RoomData *room); - void clear_data() override; - Program *program; Matrix *matrix; MatrixChatPage *chat_page; @@ -401,8 +397,6 @@ namespace QuickMedia { void clear_search(); - void clear_data(); - MatrixQuickMedia *matrix_delegate = nullptr; Body *body = nullptr; private: @@ -428,8 +422,6 @@ namespace QuickMedia { void set_current_rooms_page(MatrixRoomsPage *rooms_page); - void clear_data(); - MatrixQuickMedia *matrix_delegate = nullptr; private: struct TagData { @@ -453,8 +445,6 @@ namespace QuickMedia { void add_body_item(std::shared_ptr body_item); void remove_body_item_by_room_id(const std::string &room_id); - - void clear_data(); private: Matrix *matrix; Body *body; @@ -570,7 +560,6 @@ namespace QuickMedia { const std::string room_id; MatrixRoomsPage *rooms_page = nullptr; - bool should_clear_data = false; Body *chat_body = nullptr; bool messages_tab_visible = false; @@ -762,16 +751,16 @@ namespace QuickMedia { PluginResult set_qm_last_read_message_timestamp(RoomData *room, int64_t timestamp); void load_qm_read_markers_from_account_data(); - PluginResult parse_sync_response(const rapidjson::Document &root, bool is_additional_messages_sync, bool initial_sync); + PluginResult parse_sync_response(const rapidjson::Document &root, bool initial_sync); PluginResult parse_notifications(const rapidjson::Value ¬ifications_json, std::function callback_func); PluginResult parse_sync_account_data(const rapidjson::Value &account_data_json); - PluginResult parse_sync_room_data(const rapidjson::Value &rooms_json, bool is_additional_messages_sync, bool initial_sync); + PluginResult parse_sync_room_data(const rapidjson::Value &rooms_json, bool initial_sync); void parse_custom_emoji(const rapidjson::Value &custom_emoji_json); void load_custom_emoji_from_cache(); PluginResult get_previous_room_messages(RoomData *room_data, bool latest_messages, size_t &num_new_messages, bool *reached_end = nullptr); void events_add_user_info(const rapidjson::Value &events_json, RoomData *room_data, int64_t timestamp); std::shared_ptr parse_user_info(const rapidjson::Value &json, const std::string &user_id, RoomData *room_data, int64_t timestamp); - void events_set_user_read_marker(const rapidjson::Value &events_json, RoomData *room_data, std::shared_ptr &me, bool is_additional_messages_sync); + void events_set_user_read_marker(const rapidjson::Value &events_json, RoomData *room_data, std::shared_ptr &me); // Returns the number of messages added size_t events_add_messages(const rapidjson::Value &events_json, RoomData *room_data, MessageDirection message_dir, bool has_unread_notifications); void events_set_room_info(const rapidjson::Value &events_json, RoomData *room_data, int64_t timestamp); @@ -793,7 +782,6 @@ namespace QuickMedia { std::string get_next_batch(); void set_next_notifications_token(std::string new_next_token); std::string get_next_notifications_token(); - void clear_sync_cache_for_new_sync(); std::shared_ptr get_user_by_id(RoomData *room, const std::string &user_id, bool *is_new_user = nullptr, bool create_if_not_found = true); std::string get_filter_cached(); void load_silenced_invites(); @@ -822,9 +810,7 @@ namespace QuickMedia { std::mutex notifications_mutex; std::thread sync_thread; - std::thread sync_additional_messages_thread; std::thread notification_thread; - MessageQueue additional_messages_queue; bool sync_running = false; bool sync_failed = false; bool sync_is_cache = false; diff --git a/plugins/utils/UniqueProcess.hpp b/plugins/utils/UniqueProcess.hpp new file mode 100644 index 0000000..a2145f9 --- /dev/null +++ b/plugins/utils/UniqueProcess.hpp @@ -0,0 +1,7 @@ +#pragma once + +namespace QuickMedia { + bool is_quickmedia_instance_already_running(const char *pid_file_dir, const char *plugin_name); + bool set_quickmedia_instance_unique(const char *pid_file_dir, const char *plugin_name); + void remove_quickmedia_instance_lock(const char *pid_file_dir, const char *plugin_name); +} \ No newline at end of file -- cgit v1.2.3