#NEWLINE# def remove_many( self , activities , batch_interface = None , trim = True , * args , **kwargs ) : #NEWLINE# #INDENT# '\n        Removes many activities from the feed\n\n        :param activities: the list of activities to remove\n        ' #NEWLINE# self . trim ( ) #NEWLINE# current_activities = kwargs . pop ( 'current_activities' , None ) #NEWLINE# if ( current_activities is None ) : #NEWLINE# #INDENT# current_activities = self . get_activity_slice ( stop = self . max_length , rehydrate = False ) #NEWLINE# #UNINDENT# ( new , deleted , changed ) = ( [ ] , [ ] , [ ] ) #NEWLINE# getid = ( lambda a : getattr ( a , 'serialization_id' , a ) ) #NEWLINE# activities_to_remove = set ( ( getid ( a ) for a in activities ) ) #NEWLINE# activity_dict = dict ( ( ( getid ( a ) , a ) for a in activities ) ) #NEWLINE# activity_remove_dict = defaultdict ( list ) #NEWLINE# for aggregated in getid : #NEWLINE# #INDENT# for activity_id in aggregated . activity_ids : #NEWLINE# #INDENT# if ( activity_id in activities_to_remove ) : #NEWLINE# #INDENT# activity_remove_dict [ aggregated ] . append ( activity_id ) #NEWLINE# activities_to_remove . discard ( activity_id ) #NEWLINE# #UNINDENT# #UNINDENT# if ( not activities_to_remove ) : #NEWLINE# #INDENT# break #NEWLINE# #UNINDENT# #UNINDENT# hydrated_aggregated = activity_remove_dict . keys ( ) #NEWLINE# if self . needs_hydration ( hydrated_aggregated ) : #NEWLINE# #INDENT# hydrated_aggregated = self . hydrate_activities ( hydrated_aggregated ) #NEWLINE# #UNINDENT# hydrate_dict = dict ( ( ( a . group , a ) for a in hydrated_aggregated ) ) #NEWLINE# for ( aggregated , activity_ids_to_remove ) in activity_remove_dict . items ( ) : #NEWLINE# #INDENT# aggregated = hydrate_dict . get ( aggregated . group ) #NEWLINE# if ( len ( aggregated ) == len ( activity_ids_to_remove ) ) : #NEWLINE# #INDENT# deleted . append ( aggregated ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# original = copy . deepcopy ( aggregated ) #NEWLINE# activities_to_remove = map ( activity_dict . get , activity_ids_to_remove ) #NEWLINE# aggregated . remove_many ( activities_to_remove ) #NEWLINE# changed . append ( ( original , aggregated ) ) #NEWLINE# #UNINDENT# #UNINDENT# new_aggregated = self . _update_from_diff ( new , changed , deleted ) #NEWLINE# return new_aggregated