Skip to content

Commit

Permalink
get_tags
Browse files Browse the repository at this point in the history
  • Loading branch information
isteric-senior committed Dec 14, 2020
1 parent 181b90d commit 5213cdf
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
8 changes: 8 additions & 0 deletions plugins/tags/include/golos/plugins/tags/plugin.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,16 @@ namespace golos { namespace plugins { namespace tags {
using plugins::json_rpc::msg_pack;
using namespace golos::api;

using tag_map = std::map<std::string, tag_api_object>;

using tags_used_by_author_r = std::vector<std::pair<std::string, uint32_t>>;

struct get_languages_result {
std::set<std::string> languages;
};

DEFINE_API_ARGS(get_trending_tags, msg_pack, std::vector<tag_api_object>)
DEFINE_API_ARGS(get_tags, msg_pack, tag_map)
DEFINE_API_ARGS(get_tags_used_by_author, msg_pack, tags_used_by_author_r)
DEFINE_API_ARGS(get_discussions_by_payout, msg_pack, std::vector<discussion>)
DEFINE_API_ARGS(get_discussions_by_trending, msg_pack, std::vector<discussion>)
Expand Down Expand Up @@ -49,6 +52,11 @@ namespace golos { namespace plugins { namespace tags {
*/
(get_trending_tags)

/**
* Return the tag statistics.
*/
(get_tags)

/**
* Used to retrieve the list of first payout discussions sorted by rshares^2 amount
* @param query @ref discussion_query
Expand Down
26 changes: 26 additions & 0 deletions plugins/tags/plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ namespace golos { namespace plugins { namespace tags {

std::vector<tag_api_object> get_trending_tags(const std::string& after, uint32_t limit) const;

tag_map get_tags(std::set<std::string> tags) const;

std::vector<std::pair<std::string, uint32_t>> get_tags_used_by_author(const std::string& author) const;

std::vector<discussion> get_replies_by_last_update(
Expand Down Expand Up @@ -855,6 +857,30 @@ namespace golos { namespace plugins { namespace tags {
});
}

tag_map tags_plugin::impl::get_tags(std::set<std::string> tags) const {
tag_map result;

const auto& idx = database().get_index<tags::tag_stats_index, tags::by_tag>();
for (auto& tag : tags) {
auto itr = idx.find(std::make_tuple(tags::tag_type::tag, tag));
if (itr != idx.end()) {
result[tag] = *itr;
}
}

return result;
}

DEFINE_API(tags_plugin, get_tags) {
PLUGIN_API_VALIDATE_ARGS(
(std::set<std::string>, tags)
);

return pimpl->database().with_weak_read_lock([&]() {
return pimpl->get_tags(tags);
});
}

std::vector<std::pair<std::string, uint32_t>> tags_plugin::impl::get_tags_used_by_author(
const std::string& author
) const {
Expand Down

0 comments on commit 5213cdf

Please sign in to comment.