#NEWLINE# @ classmethod #NEWLINE# @ gen . coroutine #NEWLINE# def _GetAllContactsWithDedup( cls , client , user_id ) : #NEWLINE# #INDENT# "Query for all contacts and split into a dictionary of deduped contacts which is keyed by contact_id\n    and a list of contacts that can be deleted because they're unnecessary.\n    Returns: tuple of (retained_contacts_dict, contacts_to_delete_list)\n    " #NEWLINE# contacts_to_delete = [ ] #NEWLINE# contacts_to_retain = dict ( ) #NEWLINE# existing_contacts = ( yield gen . Task ( Contact . RangeQuery , client , hash_key = user_id , range_desc = None , limit = ( Contact . MAX_CONTACTS_LIMIT * 2 ) , col_names = [ 'contact_id' , 'labels' , 'contact_source' ] , scan_forward = True ) ) #NEWLINE# for existing_contact in existing_contacts : #NEWLINE# #INDENT# older_existing_contact = contacts_to_retain . pop ( existing_contact . contact_id , None ) #NEWLINE# if ( older_existing_contact is not None ) : #NEWLINE# #INDENT# contacts_to_delete . append ( user_id ) #NEWLINE# #UNINDENT# contacts_to_retain [ existing_contact . contact_id ] = existing_contact #NEWLINE# #UNINDENT# raise gen . Return ( ( contacts_to_retain , contacts_to_delete ) )