Skip to content

Commit

Permalink
booru/page: Use single curler for posts and count
Browse files Browse the repository at this point in the history
  • Loading branch information
ahodesuka committed Jan 23, 2018
1 parent 91c4294 commit b4605b1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
16 changes: 7 additions & 9 deletions src/booru/page.cc
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ Page::Page(Gtk::Menu *menu)
Page::~Page()
{
m_Curler.cancel();
m_CountsCurler.cancel();

if (m_GetPostsThread.joinable())
m_GetPostsThread.join();
Expand Down Expand Up @@ -116,7 +115,6 @@ void Page::search(const std::shared_ptr<Site> &site)
if (!ask_cancel_save())
return;

m_CountsCurler.cancel();
m_Curler.cancel();

cancel_save();
Expand Down Expand Up @@ -148,7 +146,6 @@ void Page::search(const std::shared_ptr<Site> &site)

m_Curler.set_share_handle(m_Site->get_share_handle());
m_Curler.set_referer(m_Site->get_url());
m_CountsCurler.set_referer(m_Site->get_url());

get_posts();
}
Expand Down Expand Up @@ -249,7 +246,6 @@ void Page::get_posts()
}

tags = m_Curler.escape(tags);
m_Curler.set_url(m_Site->get_posts_url(tags, m_Page));

m_GetPostsThread = std::thread([ &, tags ]()
{
Expand All @@ -258,23 +254,25 @@ void Page::get_posts()
// Get it from thier counts api
if (m_Page == 1 && m_Site->get_type() == Site::Type::DANBOORU)
{
m_CountsCurler.set_url(m_Site->get_url() + "/counts/posts.xml?tags=" + tags);
if (m_CountsCurler.perform())
m_Curler.set_url(m_Site->get_url() + "/counts/posts.xml?tags=" + tags);
if (m_Curler.perform())
{
try
{
xml::Document doc(reinterpret_cast<char*>(m_CountsCurler.get_data()),
m_CountsCurler.get_data_size());
xml::Document doc(reinterpret_cast<char*>(m_Curler.get_data()),
m_Curler.get_data_size());
postsCount = std::stoul(doc.get_children()[0].get_value());
}
catch (const std::runtime_error &e) { }
}
else if (m_CountsCurler.is_cancelled())
else if (m_Curler.is_cancelled())
{
return;
}
}

m_Curler.set_url(m_Site->get_posts_url(tags, m_Page));

if (m_Site->get_type() == Site::Type::GELBOORU)
m_Curler.set_cookie_file(m_Site->get_cookie());
else
Expand Down
2 changes: 1 addition & 1 deletion src/booru/page.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ namespace AhoViewer

std::shared_ptr<ImageList> m_ImageList;
std::shared_ptr<Site> m_Site;
Curler m_Curler, m_CountsCurler;
Curler m_Curler;

// m_Tags stores tags that are inside the entry
// while m_SearchTags are the whitespace trimmed tags or *
Expand Down

0 comments on commit b4605b1

Please sign in to comment.