Skip to content

Commit

Permalink
Revert "Issue #1947 ( Follow/Tags Iterator Optimization )"
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Vandeberg authored Jan 16, 2018
1 parent 159a143 commit 5d04907
Show file tree
Hide file tree
Showing 6 changed files with 124 additions and 409 deletions.
1 change: 0 additions & 1 deletion libraries/plugins/follow/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ add_library( follow_plugin
follow_plugin.cpp
follow_operations.cpp
follow_evaluators.cpp
inc_performance.cpp
)

target_link_libraries( follow_plugin chain_plugin )
Expand Down
67 changes: 36 additions & 31 deletions libraries/plugins/follow/follow_evaluators.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#include <steem/plugins/follow/follow_plugin.hpp>
#include <steem/plugins/follow/follow_operations.hpp>
#include <steem/plugins/follow/follow_objects.hpp>
#include <steem/plugins/follow/inc_performance.hpp>

#include <steem/chain/account_object.hpp>
#include <steem/chain/comment_object.hpp>
Expand Down Expand Up @@ -122,8 +121,6 @@ void reblog_evaluator::do_apply( const reblog_operation& o )
{
try
{
performance perf( _db );

const auto& c = _db.get_comment( o.author, o.permlink );
FC_ASSERT( c.parent_author.size() == 0, "Only top level posts can be reblogged" );

Expand Down Expand Up @@ -163,52 +160,60 @@ void reblog_evaluator::do_apply( const reblog_operation& o )
});
}

const auto& feed_idx = _db.get_index< feed_index >().indices().get< by_feed >();
const auto& comment_idx = _db.get_index< feed_index >().indices().get< by_comment >();
const auto& idx = _db.get_index< follow_index >().indices().get< by_following_follower >();
const auto& old_feed_idx = _db.get_index< feed_index >().indices().get< by_feed >();
auto itr = idx.find( o.account );

performance_data pd;

if( _db.head_block_time() >= _plugin->start_feeds )
{
while( itr != idx.end() && itr->following == o.account )
{

if( itr->what & ( 1 << blog ) )
{
auto feed_itr = comment_idx.find( boost::make_tuple( c.id, itr->follower ) );
bool is_empty = feed_itr == comment_idx.end();
uint32_t next_id = 0;
auto last_feed = feed_idx.lower_bound( itr->follower );

pd.init( o.account, _db.head_block_time(), c.id, is_empty, is_empty ? 0 : feed_itr->account_feed_id );
uint32_t next_id = perf.delete_old_objects< performance_data::t_creation_type::full_feed >( old_feed_idx, itr->follower, _plugin->max_feed_size, pd );
if( last_feed != feed_idx.end() && last_feed->account == itr->follower )
{
next_id = last_feed->account_feed_id + 1;
}

if( pd.s.creation )
auto feed_itr = comment_idx.find( boost::make_tuple( c.id, itr->follower ) );

if( feed_itr == comment_idx.end() )
{
if( is_empty )
_db.create< feed_object >( [&]( feed_object& f )
{
_db.create< feed_object >( [&]( feed_object& f )
{
f.account = itr->follower;
f.reblogged_by.push_back( o.account );
f.first_reblogged_by = o.account;
f.first_reblogged_on = _db.head_block_time();
f.comment = c.id;
f.account_feed_id = next_id;
});
}
else
f.account = itr->follower;
f.reblogged_by.push_back( o.account );
f.first_reblogged_by = o.account;
f.first_reblogged_on = _db.head_block_time();
f.comment = c.id;
f.reblogs = 1;
f.account_feed_id = next_id;
});
}
else
{
_db.modify( *feed_itr, [&]( feed_object& f )
{
if( pd.s.allow_modify )
{
_db.modify( *feed_itr, [&]( feed_object& f )
{
f.reblogged_by.push_back( o.account );
});
}
}
f.reblogged_by.push_back( o.account );
f.reblogs++;
});
}

const auto& old_feed_idx = _db.get_index< feed_index >().indices().get< by_old_feed >();
auto old_feed = old_feed_idx.lower_bound( itr->follower );

while( old_feed->account == itr->follower && next_id - old_feed->account_feed_id > _plugin->max_feed_size )
{
_db.remove( *old_feed );
old_feed = old_feed_idx.lower_bound( itr->follower );
};
}

++itr;
}
}
Expand Down
54 changes: 36 additions & 18 deletions libraries/plugins/follow/follow_plugin.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#include <steem/plugins/follow/follow_plugin.hpp>
#include <steem/plugins/follow/follow_objects.hpp>
#include <steem/plugins/follow/follow_operations.hpp>
#include <steem/plugins/follow/inc_performance.hpp>

#include <steem/chain/util/impacted.hpp>

Expand Down Expand Up @@ -136,10 +135,8 @@ struct post_operation_visitor
{
follow_plugin_impl& _plugin;

performance perf;

post_operation_visitor( follow_plugin_impl& plugin )
: _plugin( plugin ), perf( plugin._db ) {}
: _plugin( plugin ) {}

typedef void result_type;

Expand Down Expand Up @@ -189,54 +186,75 @@ struct post_operation_visitor

const auto& idx = db.get_index< follow_index >().indices().get< by_following_follower >();
const auto& comment_idx = db.get_index< feed_index >().indices().get< by_comment >();
const auto& old_feed_idx = db.get_index< feed_index >().indices().get< by_feed >();
auto itr = idx.find( op.author );

performance_data pd;
const auto& feed_idx = db.get_index< feed_index >().indices().get< by_feed >();

if( db.head_block_time() >= _plugin._self.start_feeds )
{
while( itr != idx.end() && itr->following == op.author )
{
if( itr->what & ( 1 << blog ) )
{
auto feed_itr = comment_idx.find( boost::make_tuple( c.id, itr->follower ) );
bool is_empty = feed_itr == comment_idx.end();
uint32_t next_id = 0;
auto last_feed = feed_idx.lower_bound( itr->follower );

pd.init( c.id, is_empty );
uint32_t next_id = perf.delete_old_objects< performance_data::t_creation_type::part_feed >( old_feed_idx, itr->follower, _plugin._self.max_feed_size, pd );
if( last_feed != feed_idx.end() && last_feed->account == itr->follower )
{
next_id = last_feed->account_feed_id + 1;
}

if( pd.s.creation && is_empty )
if( comment_idx.find( boost::make_tuple( c.id, itr->follower ) ) == comment_idx.end() )
{
db.create< feed_object >( [&]( feed_object& f )
{
f.account = itr->follower;
f.comment = c.id;
f.account_feed_id = next_id;
});
}

const auto& old_feed_idx = db.get_index< feed_index >().indices().get< by_old_feed >();
auto old_feed = old_feed_idx.lower_bound( itr->follower );

while( old_feed->account == itr->follower && next_id - old_feed->account_feed_id > _plugin._self.max_feed_size )
{
db.remove( *old_feed );
old_feed = old_feed_idx.lower_bound( itr->follower );
}
}
}

++itr;
}
}

const auto& blog_idx = db.get_index< blog_index >().indices().get< by_blog >();
const auto& comment_blog_idx = db.get_index< blog_index >().indices().get< by_comment >();
auto blog_itr = comment_blog_idx.find( boost::make_tuple( c.id, op.author ) );
const auto& old_blog_idx = db.get_index< blog_index >().indices().get< by_blog >();
bool is_empty = blog_itr == comment_blog_idx.end();
auto last_blog = blog_idx.lower_bound( op.author );
uint32_t next_id = 0;

pd.init( c.id, is_empty );
uint32_t next_id = perf.delete_old_objects< performance_data::t_creation_type::full_blog >( old_blog_idx, op.author, _plugin._self.max_feed_size, pd );
if( last_blog != blog_idx.end() && last_blog->account == op.author )
{
next_id = last_blog->blog_feed_id + 1;
}

if( pd.s.creation && is_empty )
if( comment_blog_idx.find( boost::make_tuple( c.id, op.author ) ) == comment_blog_idx.end() )
{
db.create< blog_object >( [&]( blog_object& b)
{
b.account = op.author;
b.comment = c.id;
b.blog_feed_id = next_id;
});

const auto& old_blog_idx = db.get_index< blog_index >().indices().get< by_old_blog >();
auto old_blog = old_blog_idx.lower_bound( op.author );

while( old_blog->account == op.author && next_id - old_blog->blog_feed_id > _plugin._self.max_feed_size )
{
db.remove( *old_blog );
old_blog = old_blog_idx.lower_bound( op.author );
}
}
}
FC_LOG_AND_RETHROW()
Expand Down
Loading

0 comments on commit 5d04907

Please sign in to comment.