Restore bloom filter usage: Check if the object changed/removed was previously subscribed (read) before sending updates back to ws clients

This commit is contained in:
elmato 2017-02-03 19:25:52 +00:00
parent 9bbbefd391
commit 342e33008c

View file

@ -160,7 +160,7 @@ class database_api_impl : public std::enable_shared_from_this<database_api_impl>
{ {
if( !_subscribe_callback ) if( !_subscribe_callback )
return false; return false;
return true;
return _subscribe_filter.contains( i ); return _subscribe_filter.contains( i );
} }
@ -1818,8 +1818,10 @@ void database_api_impl::on_objects_removed( const vector<const object*>& objs )
vector<variant> updates; vector<variant> updates;
updates.reserve(objs.size()); updates.reserve(objs.size());
for( auto obj : objs ) for( auto obj : objs ) {
updates.emplace_back( obj->id ); if ( is_subscribed_to_item(obj->id) )
updates.emplace_back( obj->id );
}
broadcast_updates( updates ); broadcast_updates( updates );
} }
@ -1859,7 +1861,7 @@ void database_api_impl::on_objects_changed(const vector<object_id_type>& ids)
for(auto id : ids) for(auto id : ids)
{ {
const object* obj = nullptr; const object* obj = nullptr;
if( _subscribe_callback ) if( is_subscribed_to_item(id) )
{ {
obj = _db.find_object( id ); obj = _db.find_object( id );
if( obj ) if( obj )
@ -1874,7 +1876,7 @@ void database_api_impl::on_objects_changed(const vector<object_id_type>& ids)
if( _market_subscriptions.size() ) if( _market_subscriptions.size() )
{ {
if( !_subscribe_callback ) if( !is_subscribed_to_item(id) )
obj = _db.find_object( id ); obj = _db.find_object( id );
if( obj ) if( obj )
{ {
@ -1895,7 +1897,7 @@ void database_api_impl::on_objects_changed(const vector<object_id_type>& ids)
/// if a connection hangs then this could get backed up and result in /// if a connection hangs then this could get backed up and result in
/// a failure to exit cleanly. /// a failure to exit cleanly.
fc::async([capture_this,this,updates,market_broadcast_queue](){ fc::async([capture_this,this,updates,market_broadcast_queue](){
if( _subscribe_callback ) _subscribe_callback( updates ); if( _subscribe_callback && updates.size() ) _subscribe_callback( updates );
for( const auto& item : market_broadcast_queue ) for( const auto& item : market_broadcast_queue )
{ {