Skip to content

Commit

Permalink
Merge pull request #428 from steemit/20160913-follow
Browse files Browse the repository at this point in the history
20160913 follow
  • Loading branch information
Michael Vandeberg authored Sep 16, 2016
2 parents b7589d9 + 1f4f6b4 commit 354cd6b
Show file tree
Hide file tree
Showing 6 changed files with 145 additions and 38 deletions.
152 changes: 127 additions & 25 deletions libraries/app/database_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1275,6 +1275,8 @@ vector<discussion> database_api::get_discussions_by_feed( const discussion_query
try
{
result.push_back( get_discussion( feed_itr->comment ) );
if( feed_itr->first_reblogged_by != account_id_type() )
result.back().first_reblogged_by = feed_itr->first_reblogged_by( my->_db ).name;
}
catch ( const fc::exception& e )
{
Expand All @@ -1286,6 +1288,91 @@ vector<discussion> database_api::get_discussions_by_feed( const discussion_query
return result;
}

vector<discussion> database_api::get_discussions_by_blog( const discussion_query& query )const
{
query.validate();
FC_ASSERT( my->_follow_api, "Node is not running the follow plugin" );
auto start_author = query.start_author ? *( query.start_author ) : "";
auto start_permlink = query.start_permlink ? *( query.start_permlink ) : "";

const auto& account = my->_db.get_account( query.tag );

const auto& c_idx = my->_db.get_index_type< follow::blog_index >().indices().get< follow::by_comment >();
const auto& b_idx = my->_db.get_index_type< follow::blog_index >().indices().get< follow::by_blog >();
auto blog_itr = b_idx.lower_bound( account.id );

if( start_author.size() || start_permlink.size() )
{
auto start_c = c_idx.find( boost::make_tuple( my->_db.get_comment( start_author, start_permlink ).id, account.id ) );
FC_ASSERT( start_c != c_idx.end(), "Comment is not in account's blog" );
blog_itr = b_idx.iterator_to( *start_c );
}

vector< discussion > result;
result.reserve( query.limit );

while( result.size() < query.limit && blog_itr != b_idx.end() )
{
if( blog_itr->account != account.id )
break;
try
{
result.push_back( get_discussion( blog_itr->comment ) );
}
catch ( const fc::exception& e )
{
edump((e.to_detail_string()));
}

++blog_itr;
}
return result;
}

vector<discussion> database_api::get_discussions_by_comments( const discussion_query& query )const
{
query.validate();
FC_ASSERT( query.start_author, "Must get comments for a specific author" );
auto start_author = *( query.start_author );
auto start_permlink = query.start_permlink ? *( query.start_permlink ) : "";

const auto& account = my->_db.get_account( start_author );

const auto& c_idx = my->_db.get_index_type< comment_index >().indices().get< by_permlink >();
const auto& t_idx = my->_db.get_index_type< comment_index >().indices().get< by_author_last_update >();
auto comment_itr = t_idx.lower_bound( start_author );

if( start_permlink.size() )
{
auto start_c = c_idx.find( boost::make_tuple( start_author, start_permlink ) );
FC_ASSERT( start_c != c_idx.end(), "Comment is not in account's comments" );
comment_itr = t_idx.iterator_to( *start_c );
}

vector< discussion > result;
result.reserve( query.limit );

while( result.size() < query.limit && comment_itr != t_idx.end() )
{
if( comment_itr->author != start_author )
break;
if( comment_itr->parent_author.size() > 0 )
{
try
{
result.push_back( get_discussion( comment_itr->id ) );
}
catch( const fc::exception& e )
{
edump( (e.to_detail_string() ) );
}
}

++comment_itr;
}
return result;
}

vector<category_object> database_api::get_trending_categories( string after, uint32_t limit )const {
limit = std::min( limit, uint32_t(100) );
vector<category_object> result; result.reserve( limit );
Expand Down Expand Up @@ -1536,31 +1623,44 @@ state database_api::get_state( string path )const
}
eacnt.recent_replies->push_back( reply_ref );
}
} else if( part[1] == "posts" ) {
int count = 0;
const auto& pidx = my->_db.get_index_type<comment_index>().indices().get<by_author_last_update>();
auto itr = pidx.lower_bound( boost::make_tuple(acnt, time_point_sec::maximum() ) );
eacnt.posts = vector<string>();
while( itr != pidx.end() && itr->author == acnt && count < 20 ) {
eacnt.posts->push_back(itr->permlink);
_state.content[acnt+"/"+itr->permlink] = *itr;
set_pending_payout( _state.content[acnt+"/"+itr->permlink] );
++itr;
++count;
}
} else if( part[1].size() == 0 || part[1] == "blog" ) {
int count = 0;
const auto& pidx = my->_db.get_index_type<comment_index>().indices().get<by_blog>();
auto itr = pidx.lower_bound( boost::make_tuple(acnt, std::string(""), time_point_sec::maximum() ) );
eacnt.blog = vector<string>();
while( itr != pidx.end() && itr->author == acnt && count < 20 && !itr->parent_author.size() ) {
eacnt.blog->push_back(itr->permlink);
_state.content[acnt+"/"+itr->permlink] = *itr;
set_pending_payout( _state.content[acnt+"/"+itr->permlink] );
++itr;
++count;
}
} else if( part[1].size() == 0 || part[1] == "feed" )
}
else if( part[1] == "posts" || part[1] == "comments" )
{
int count = 0;
const auto& pidx = my->_db.get_index_type<comment_index>().indices().get<by_author_last_update>();
auto itr = pidx.lower_bound( acnt );
eacnt.posts = vector<string>();

while( itr != pidx.end() && itr->author == acnt && count < 20 )
{
if( itr->parent_author.size() )
{
eacnt.posts->push_back(itr->permlink);
_state.content[acnt+"/"+itr->permlink] = *itr;
set_pending_payout( _state.content[acnt+"/"+itr->permlink] );
++count;
}

++itr;
}
}
else if( part[1].size() == 0 || part[1] == "blog" )
{
if( my->_follow_api )
{
auto blog = my->_follow_api->get_blog_entries( eacnt.name, 0, 20 );
eacnt.blog = vector< string >();

for( auto b: blog )
{
const auto link = b.author + "/" + b.permlink;
eacnt.blog->push_back( link );
_state.content[ link ] = my->_db.get_comment( b.author, b.permlink );
set_pending_payout( _state.content[ link ] );
}
}
}
else if( part[1].size() == 0 || part[1] == "feed" )
{
if( my->_follow_api )
{
Expand All @@ -1573,6 +1673,8 @@ state database_api::get_state( string path )const
eacnt.feed->push_back( link );
_state.content[ link ] = my->_db.get_comment( f.author, f.permlink );
set_pending_payout( _state.content[ link ] );
if( f.reblog_by.size() )
_state.content[link].first_reblogged_by = f.reblog_by;
}
}
}
Expand Down
5 changes: 4 additions & 1 deletion libraries/app/include/steemit/app/database_api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -332,9 +332,10 @@ class database_api
vector<discussion> get_discussions_by_children( const discussion_query& query )const;
vector<discussion> get_discussions_by_hot( const discussion_query& query )const;
vector<discussion> get_discussions_by_feed( const discussion_query& query )const;
vector<discussion> get_discussions_by_blog( const discussion_query& query )const;
vector<discussion> get_discussions_by_comments( const discussion_query& query )const;
vector<discussion> get_discussions_by_promoted( const discussion_query& query )const;


///@}

/**
Expand Down Expand Up @@ -445,6 +446,8 @@ FC_API(steemit::app::database_api,
(get_discussions_by_children)
(get_discussions_by_hot)
(get_discussions_by_feed)
(get_discussions_by_blog)
(get_discussions_by_comments)
(get_discussions_by_promoted)

// Blocks and transactions
Expand Down
3 changes: 2 additions & 1 deletion libraries/app/include/steemit/app/state.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ namespace steemit { namespace app {
vector<string> replies; ///< author/slug mapping
share_type author_reputation = 0;
asset promoted = asset(0, SBD_SYMBOL);
optional<string> first_reblogged_by;
};

/**
Expand Down Expand Up @@ -176,7 +177,7 @@ FC_REFLECT( steemit::app::account_vote, (authorperm)(weight)(rshares)(percent)(t

FC_REFLECT( steemit::app::discussion_index, (category)(trending)(trending30)(updated)(created)(responses)(active)(votes)(maturing)(best)(hot)(promoted)(cashout) )
FC_REFLECT( steemit::app::category_index, (trending)(active)(recent)(best) )
FC_REFLECT_DERIVED( steemit::app::discussion, (steemit::chain::comment_object), (url)(root_title)(pending_payout_value)(total_pending_payout_value)(active_votes)(replies)(author_reputation)(promoted) )
FC_REFLECT_DERIVED( steemit::app::discussion, (steemit::chain::comment_object), (url)(root_title)(pending_payout_value)(total_pending_payout_value)(active_votes)(replies)(author_reputation)(promoted)(first_reblogged_by) )

FC_REFLECT( steemit::app::state, (current_route)(props)(category_idx)(categories)(content)(accounts)(pow_queue)(witnesses)(discussion_idx)(witness_schedule)(feed_price)(error)(market_data) )

Expand Down
6 changes: 4 additions & 2 deletions libraries/chain/steem_evaluator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1280,7 +1280,8 @@ void custom_json_evaluator::do_apply( const custom_json_operation& o )
}
catch( const fc::exception& e )
{
//elog( "Caught exception processing custom_json_operation:\n${e}", ("e", e.to_detail_string()) );
if( d.is_producing() )
throw e;
}
catch(...)
{
Expand All @@ -1304,7 +1305,8 @@ void custom_binary_evaluator::do_apply( const custom_binary_operation& o )
}
catch( const fc::exception& e )
{
//elog( "Caught exception processing custom_json_operation:\n${e}", ("e", e.to_detail_string()) );
if( d.is_producing() )
throw e;
}
catch(...)
{
Expand Down
16 changes: 7 additions & 9 deletions libraries/plugins/follow/follow_evaluators.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ void reblog_evaluator::do_apply( const reblog_operation& o )
{
auto& db = _plugin->database();
const auto& c = db.get_comment( o.author, o.permlink );
if( c.parent_author.size() > 0 ) return;
FC_ASSERT( c.parent_author.size() == 0, "Only top level posts can be reblogged" );

const auto& reblog_account = db.get_account( o.account );
const auto& blog_idx = db.get_index_type< blog_index >().indices().get< by_blog >();
Expand All @@ -82,15 +82,13 @@ void reblog_evaluator::do_apply( const reblog_operation& o )

auto blog_itr = blog_comment_idx.find( boost::make_tuple( c.id, reblog_account.id ) );

if( blog_itr == blog_comment_idx.end() )
FC_ASSERT( blog_itr == blog_comment_idx.end(), "Account has already reblogged this post" );
db.create< blog_object >( [&]( blog_object& b )
{
db.create< blog_object >( [&]( blog_object& b )
{
b.account = reblog_account.id;
b.comment = c.id;
b.blog_feed_id = next_blog_id;
});
}
b.account = reblog_account.id;
b.comment = c.id;
b.blog_feed_id = next_blog_id;
});

const auto& feed_idx = db.get_index_type< feed_index >().indices().get< by_feed >();
const auto& comment_idx = db.get_index_type< feed_index >().indices().get< by_comment >();
Expand Down
1 change: 1 addition & 0 deletions libraries/plugins/follow/follow_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ struct pre_operation_visitor
const auto* comment = db.find_comment( op.author, op.permlink );

if( comment == nullptr ) return;
if( comment->parent_author.size() ) return;

const auto& feed_idx = db.get_index_type< feed_index >().indices().get< by_comment >();
auto itr = feed_idx.lower_bound( comment->id );
Expand Down

0 comments on commit 354cd6b

Please sign in to comment.