@@ -182,7 +182,17 @@ namespace golos {
182182 Args... args
183183 ) const;
184184
185- std::vector<discussion> get_content_replies(std::string author, std::string permlink) const;
185+ void select_content_replies(
186+ std::vector<discussion>& result, const std::string &author, const std::string &permlink
187+ ) const;
188+
189+ std::vector<discussion> get_content_replies(
190+ const std::string &author, const std::string &permlink
191+ ) const;
192+
193+ std::vector<discussion> get_all_content_replies(
194+ const std::string &author, const std::string &permlink
195+ ) const;
186196
187197 std::vector<tag_api_object> get_trending_tags(std::string after, uint32_t limit) const;
188198
@@ -325,20 +335,31 @@ namespace golos {
325335 }
326336 }
327337
328- std::vector<discussion> social_network_t::impl::get_content_replies(std::string author, std::string permlink) const {
338+ void social_network_t::impl::select_content_replies(
339+ std::vector<discussion> &result, const std::string &author, const std::string &permlink
340+ ) const {
329341 account_name_type acc_name = account_name_type(author);
330342 const auto &by_permlink_idx = database().get_index<comment_index>().indices().get<by_parent>();
331343 auto itr = by_permlink_idx.find(boost::make_tuple(acc_name, permlink));
332- std::vector<discussion> result;
333- while (itr != by_permlink_idx.end() && itr->parent_author == author &&
334- to_string(itr->parent_permlink) == permlink) {
344+ while (
345+ itr != by_permlink_idx.end() &&
346+ itr->parent_author == author &&
347+ !strcmp(itr->parent_permlink.c_str(), permlink.c_str())
348+ ) {
335349 discussion push_discussion(*itr);
336350 push_discussion.active_votes = get_active_votes(author, permlink);
337351
338352 result.emplace_back(*itr);
339353 set_pending_payout(result.back());
340354 ++itr;
341355 }
356+ }
357+
358+ std::vector<discussion> social_network_t::impl::get_content_replies(
359+ const std::string &author, const std::string &permlink
360+ ) const {
361+ std::vector<discussion> result;
362+ select_content_replies(result, author, permlink);
342363 return result;
343364 }
344365
@@ -351,6 +372,27 @@ namespace golos {
351372 });
352373 }
353374
375+ std::vector<discussion> social_network_t::impl::get_all_content_replies(
376+ const std::string &author, const std::string &permlink
377+ ) const {
378+ std::vector<discussion> result;
379+ select_content_replies(result, author, permlink);
380+ for (std::size_t i = 0; i < result.size(); ++i) {
381+ if (result[i].children > 0) {
382+ select_content_replies(result, result[i].author, result[i].permlink);
383+ }
384+ }
385+ return result;
386+ }
387+
388+ DEFINE_API(social_network_t, get_all_content_replies) {
389+ CHECK_ARG_SIZE(2)
390+ auto author = args.args->at(0).as<string>();
391+ auto permlink = args.args->at(1).as<string>();
392+ return pimpl->database().with_read_lock([&]() {
393+ return pimpl->get_all_content_replies(author, permlink);
394+ });
395+ }
354396 boost::multiprecision::uint256_t to256(const fc::uint128_t &t) {
355397 boost::multiprecision::uint256_t result(t.high_bits());
356398 result <<= 65;
0 commit comments