Skip to content

Commit

Permalink
Merge pull request steemit#2537 from steemit/2535-get-content-tags-dep
Browse files Browse the repository at this point in the history
Remove tags_api dependency from get_content
  • Loading branch information
Michael Vandeberg authored Jun 12, 2018
2 parents 5079bca + f4082a2 commit 22ebcf0
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 111 deletions.
98 changes: 81 additions & 17 deletions libraries/plugins/apis/condenser_api/condenser_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -700,12 +700,10 @@ namespace detail
_state.accounts[a].reputation = _reputation_api->get_account_reputations( { a, 1 } ).reputations[0].reputation;
}
}
if( _tags_api )
for( auto& d : _state.content )
{
for( auto& d : _state.content )
{
d.second.active_votes = _tags_api->get_active_votes( { d.second.author, d.second.permlink } ).votes;
}
d.second.active_votes = get_active_votes( { fc::variant( d.second.author ), fc::variant( d.second.permlink ) } );
}
_state.witness_schedule = _database_api->get_witness_schedule( {} );
Expand Down Expand Up @@ -1303,9 +1301,37 @@ namespace detail
DEFINE_API_IMPL( condenser_api_impl, get_active_votes )
{
CHECK_ARG_SIZE( 2 )
FC_ASSERT( _tags_api, "tags_api_plugin not enabled." );
return _tags_api->get_active_votes( { args[0].as< account_name_type >(), args[1].as< string >() } ).votes;
vector< tags::vote_state > votes;
const auto& comment = _db.get_comment( args[0].as< account_name_type >(), args[1].as< string >() );
const auto& idx = _db.get_index< chain::comment_vote_index, chain::by_comment_voter >();
chain::comment_id_type cid(comment.id);
auto itr = idx.lower_bound( cid );
while( itr != idx.end() && itr->comment == cid )
{
const auto& vo = _db.get( itr->voter );
tags::vote_state vstate;
vstate.voter = vo.name;
vstate.weight = itr->weight;
vstate.rshares = itr->rshares;
vstate.percent = itr->vote_percent;
vstate.time = itr->last_update;
if( _follow_api )
{
auto reps = _follow_api->get_account_reputations( follow::get_account_reputations_args( { vo.name, 1 } ) ).reputations;
if( reps.size() )
{
vstate.reputation = reps[0].reputation;
}
}
votes.push_back( vstate );
++itr;
}
return votes;
}
DEFINE_API_IMPL( condenser_api_impl, get_account_votes )
Expand Down Expand Up @@ -1340,22 +1366,35 @@ namespace detail
DEFINE_API_IMPL( condenser_api_impl, get_content )
{
CHECK_ARG_SIZE( 2 )
FC_ASSERT( _tags_api, "tags_api_plugin not enabled." );
return discussion( _tags_api->get_discussion( { args[0].as< account_name_type >(), args[1].as< string >() } ) );
auto comments = _database_api->find_comments( { { { args[0].as< account_name_type >(), args[1].as< string >() } } } );
if( comments.comments.size() == 0 )
{
return discussion();
}
discussion content( comments.comments[0] );
set_pending_payout( content );
return content;
}
DEFINE_API_IMPL( condenser_api_impl, get_content_replies )
{
CHECK_ARG_SIZE( 2 )
FC_ASSERT( _tags_api, "tags_api_plugin not enabled." );
auto discussions = _tags_api->get_content_replies( { args[0].as< account_name_type >(), args[1].as< string >() } ).discussions;
account_name_type author = args[0].as< account_name_type >();
string permlink = args[1].as< string >();
const auto& by_permlink_idx = _db.get_index< comment_index, by_parent >();
auto itr = by_permlink_idx.find( boost::make_tuple( author, permlink ) );
vector< discussion > result;
for( auto& d : discussions )
while( itr != by_permlink_idx.end() && itr->parent_author == author && to_string( itr->parent_permlink ) == permlink )
{
result.push_back( discussion( d ) );
result.push_back( discussion( database_api::api_comment_object( *itr, _db ) ) );
set_pending_payout( result.back() );
++itr;
}
return result;
Expand Down Expand Up @@ -1593,16 +1632,41 @@ namespace detail
DEFINE_API_IMPL( condenser_api_impl, get_replies_by_last_update )
{
CHECK_ARG_SIZE( 3 )
FC_ASSERT( _tags_api, "tags_api_plugin not enabled." );
auto discussions = _tags_api->get_replies_by_last_update( { args[0].as< account_name_type >(), args[1].as< string >(), args[2].as< uint32_t >() } ).discussions;
vector< discussion > result;
for( auto& d : discussions )
#ifndef IS_LOW_MEM
account_name_type start_parent_author = args[0].as< account_name_type >();
string start_permlink = args[1].as< string >();
uint32_t limit = args[2].as< uint32_t >();
FC_ASSERT( limit <= 100 );
const auto& last_update_idx = _db.get_index< comment_index, by_last_update >();
auto itr = last_update_idx.begin();
const account_name_type* parent_author = &start_parent_author;
if( start_permlink.size() )
{
result.push_back( discussion( d ) );
const auto& comment = _db.get_comment( start_parent_author, start_permlink );
itr = last_update_idx.iterator_to( comment );
parent_author = &comment.parent_author;
}
else if( start_parent_author.size() )
{
itr = last_update_idx.lower_bound( start_parent_author );
}
result.reserve( limit );
while( itr != last_update_idx.end() && result.size() < limit && itr->parent_author == *parent_author )
{
result.push_back( discussion( database_api::api_comment_object( *itr, _db ) ) );
set_pending_payout( result.back() );
result.back().active_votes = get_active_votes( { fc::variant( itr->author ), fc::variant( itr->permlink ) } );
++itr;
}
#endif
return result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -656,45 +656,14 @@ struct api_convert_request_object
time_point_sec conversion_date;
};

struct discussion
struct discussion : public api_comment_object
{
discussion() {}

discussion( const api_comment_object& c ) : api_comment_object( c ) {}

discussion( const tags::discussion& d ) :
id( d.id ),
category( d.category ),
parent_author( d.parent_author ),
parent_permlink( d.parent_permlink ),
author( d.author ),
permlink( d.permlink ),
title( d.title ),
body( d.body ),
json_metadata( d.json_metadata ),
last_update( d.last_update ),
created( d.created ),
active( d.active ),
last_payout( d.last_payout ),
depth( d.depth ),
children( d.children ),
net_rshares( d.net_rshares ),
abs_rshares( d.abs_rshares ),
vote_rshares( d.vote_rshares ),
children_abs_rshares( d.children_abs_rshares ),
cashout_time( d.cashout_time ),
max_cashout_time( d.max_cashout_time ),
total_vote_weight( d.total_vote_weight ),
reward_weight( d.reward_weight ),
total_payout_value( legacy_asset::from_asset( d.total_payout_value ) ),
curator_payout_value( legacy_asset::from_asset( d.curator_payout_value ) ),
author_rewards( d.author_rewards ),
net_votes( d.net_votes ),
root_author( d.root_author ),
root_permlink( d.root_permlink ),
max_accepted_payout( legacy_asset::from_asset( d.max_accepted_payout ) ),
percent_steem_dollars( d.percent_steem_dollars ),
allow_replies( d.allow_replies ),
allow_votes( d.allow_votes ),
allow_curation_rewards( d.allow_curation_rewards ),
beneficiaries( d.beneficiaries ),
api_comment_object( d ),
url( d.url ),
root_title( d.root_title ),
pending_payout_value( legacy_asset::from_asset( d.pending_payout_value ) ),
Expand All @@ -709,53 +678,6 @@ struct discussion
first_reblogged_on( d.first_reblogged_on )
{}


comment_id_type id;
string category;
string parent_author;
string parent_permlink;
string author;
string permlink;

string title;
string body;
string json_metadata;
time_point_sec last_update;
time_point_sec created;
time_point_sec active;
time_point_sec last_payout;

uint8_t depth = 0;
uint32_t children = 0;

share_type net_rshares;
share_type abs_rshares;
share_type vote_rshares;

share_type children_abs_rshares;
time_point_sec cashout_time;
time_point_sec max_cashout_time;
uint64_t total_vote_weight = 0;

uint16_t reward_weight = 0;

legacy_asset total_payout_value;
legacy_asset curator_payout_value;

share_type author_rewards;

int32_t net_votes = 0;

account_name_type root_author;
string root_permlink;

legacy_asset max_accepted_payout;
uint16_t percent_steem_dollars = 0;
bool allow_replies = false;
bool allow_votes = false;
bool allow_curation_rewards = false;
vector< beneficiary_route_type > beneficiaries;

string url; /// /category/@rootauthor/root_permlink#author/permlink
string root_title;
legacy_asset pending_payout_value; ///< sbd
Expand Down Expand Up @@ -1318,17 +1240,7 @@ FC_REFLECT( steem::plugins::condenser_api::api_vesting_delegation_expiration_obj
FC_REFLECT( steem::plugins::condenser_api::api_convert_request_object,
(id)(owner)(requestid)(amount)(conversion_date) )

FC_REFLECT( steem::plugins::condenser_api::discussion,
(id)(author)(permlink)
(category)(parent_author)(parent_permlink)
(title)(body)(json_metadata)(last_update)(created)(active)(last_payout)
(depth)(children)
(net_rshares)(abs_rshares)(vote_rshares)
(children_abs_rshares)(cashout_time)(max_cashout_time)
(total_vote_weight)(reward_weight)(total_payout_value)(curator_payout_value)(author_rewards)(net_votes)
(root_author)(root_permlink)
(max_accepted_payout)(percent_steem_dollars)(allow_replies)(allow_votes)(allow_curation_rewards)
(beneficiaries)
FC_REFLECT_DERIVED( steem::plugins::condenser_api::discussion, (steem::plugins::condenser_api::api_comment_object),
(url)(root_title)(pending_payout_value)(total_pending_payout_value)
(active_votes)(replies)(author_reputation)(promoted)
(body_length)(reblogged_by)(first_reblogged_by)(first_reblogged_on)
Expand Down

0 comments on commit 22ebcf0

Please sign in to comment.