#NEWLINE# @ gen . engine #NEWLINE# def _CheckMissingActivities( self , viewpoint , activities , followers , ep_photos_list , comments , callback ) : #NEWLINE# #INDENT# 'Checks that every follower, episode, photo, and comment is\n    referenced at least once by an activity.\n\n    TODO: Consider checking for missing unshare activities.\n    ' #NEWLINE# index = set ( ) #NEWLINE# index . add ( viewpoint . user_id ) #NEWLINE# has_share_new = False #NEWLINE# for activity in activities : #NEWLINE# #INDENT# if ( activity . name == 'share_new' ) : #NEWLINE# #INDENT# has_share_new = True #NEWLINE# #UNINDENT# invalidate = json . loads ( activity . json ) #NEWLINE# if ( activity . name in [ 'add_followers' , 'share_new' ] ) : #NEWLINE# #INDENT# [ index . add ( f_id ) for f_id in invalidate [ 'follower_ids' ] ] #NEWLINE# #UNINDENT# if ( activity . name == 'merge_accounts' ) : #NEWLINE# #INDENT# [ index . add ( invalidate [ 'target_user_id' ] ) ] #NEWLINE# #UNINDENT# if ( activity . name == 'post_comment' ) : #NEWLINE# #INDENT# index . add ( invalidate [ 'comment_id' ] ) #NEWLINE# #UNINDENT# if ( activity . name in [ 'share_existing' , 'share_new' , 'save_photos' ] ) : #NEWLINE# #INDENT# for item in invalidate [ 'episodes' ] : #NEWLINE# #INDENT# index . add ( item [ 'episode_id' ] ) #NEWLINE# [ index . add ( ph_id ) for ph_id in item [ 'photo_ids' ] ] #NEWLINE# #UNINDENT# #UNINDENT# if ( activity . name in [ 'upload_episode' ] ) : #NEWLINE# #INDENT# index . add ( invalidate [ 'episode_id' ] ) #NEWLINE# [ index . add ( ph_id ) for ph_id in invalidate [ 'photo_ids' ] ] #NEWLINE# #UNINDENT# #UNINDENT# missing_follower_ids = [ f . user_id for f in followers if ( f . user_id not in index ) ] #NEWLINE# if ( ( len ( ep_photos_list ) > 0 ) or ( len ( comments ) > 0 ) ) : #NEWLINE# #INDENT# for ( episode , photos , _ , _ ) in ep_photos_list : #NEWLINE# #INDENT# if ( episode . episode_id not in index ) : #NEWLINE# #INDENT# if viewpoint . IsDefault ( ) : #NEWLINE# #INDENT# if ( episode . parent_ep_id is None ) : #NEWLINE# #INDENT# ( yield gen . Task ( self . _ReportCorruption , viewpoint . viewpoint_id , 'missing upload_episode activity' , episode . episode_id , partial ( self . _RepairMissingActivities , episode . user_id , viewpoint , 'upload_episode' , ( episode , photos ) ) ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# ( yield gen . Task ( self . _ReportCorruption , viewpoint . viewpoint_id , 'missing save_photos activity' , episode . episode_id , partial ( self . _RepairMissingActivities , episode . user_id , viewpoint , 'save_photos' , ( episode , photos ) ) ) ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if ( not has_share_new ) : #NEWLINE# #INDENT# has_share_new = True #NEWLINE# ( yield gen . Task ( self . _ReportCorruption , viewpoint . viewpoint_id , 'missing share_new activity' , episode . episode_id , partial ( self . _RepairMissingActivities , episode . user_id , viewpoint , 'share_new' , ( episode , photos , missing_follower_ids ) ) ) ) #NEWLINE# missing_follower_ids = None #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# ( yield gen . Task ( self . _ReportCorruption , viewpoint . viewpoint_id , 'missing share_existing activity' , episode . episode_id , partial ( self . _RepairMissingActivities , episode . user_id , viewpoint , 'share_existing' , ( episode , photos , None ) ) ) ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# if missing_follower_ids : #NEWLINE# #INDENT# ( yield gen . Task ( self . _ReportCorruption , viewpoint . viewpoint_id , 'missing add_followers activity' , missing_follower_ids , partial ( self . _RepairMissingActivities , viewpoint . user_id , viewpoint , 'add_followers' , missing_follower_ids ) ) ) #NEWLINE# #UNINDENT# for comment in comments : #NEWLINE# #INDENT# if ( comment . comment_id not in index ) : #NEWLINE# #INDENT# ( yield gen . Task ( self . _ReportCorruption , viewpoint . viewpoint_id , 'missing post_comment activity' , comment . comment_id , partial ( self . _RepairMissingActivities , comment . user_id , viewpoint , 'post_comment' , comment . comment_id ) ) ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# callback ( )