From 4b97ef51562df8d606cb8fe21cf9b4464767febb Mon Sep 17 00:00:00 2001 From: dec05eba Date: Mon, 1 Jun 2020 21:36:58 +0200 Subject: Improve 4chan thread list performance by asynchronous update and caching --- plugins/Fourchan.hpp | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) (limited to 'plugins') diff --git a/plugins/Fourchan.hpp b/plugins/Fourchan.hpp index 6534cfd..7b76f83 100644 --- a/plugins/Fourchan.hpp +++ b/plugins/Fourchan.hpp @@ -1,11 +1,15 @@ #pragma once #include "ImageBoard.hpp" +#include +#include +#include namespace QuickMedia { class Fourchan : public ImageBoard { public: - Fourchan() : ImageBoard("4chan") {} + Fourchan(); + ~Fourchan() override; PluginResult get_front_page(BodyItems &result_items) override; SearchResult search(const std::string &url, BodyItems &result_items) override; SuggestionResult update_search_suggestions(const std::string &text, BodyItems &result_items) override; @@ -17,5 +21,22 @@ namespace QuickMedia { int get_search_delay() const override { return 150; } Page get_page_after_search() const override { return Page::IMAGE_BOARD_THREAD_LIST; } bool search_is_filter() override { return true; } + private: + PluginResult get_threads_internal(const std::string &url, BodyItems &result_items); + void set_board_url(const std::string &new_url); + std::string get_board_url(); + void set_board_thread_list(BodyItems body_items); + BodyItems get_board_thread_list(); + private: + std::string current_board_url; + std::thread thread_list_update_thread; + BodyItems cached_thread_list_items; + std::mutex board_url_mutex; + std::mutex board_list_mutex; + std::condition_variable thread_list_cached_cv; + std::mutex thread_list_cache_mutex; + std::condition_variable thread_list_update_cv; + bool thread_list_cached = false; + bool running = true; }; } \ No newline at end of file -- cgit v1.2.3