#NEWLINE# def pull_votes( self , posts ) : #NEWLINE# #INDENT# 'Pulls in the vote-status of the user for all the posts.\n        This reduces the number of queries emitted.\n        ' #NEWLINE# if ( not hasattr ( self , '_vote_cache' ) ) : #NEWLINE# #INDENT# self . _vote_cache = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# #UNINDENT# to_pull = set ( ) #NEWLINE# for post in posts : #NEWLINE# #INDENT# if ( post . id not in self . _vote_cache ) : #NEWLINE# #INDENT# to_pull . add ( post . id ) #NEWLINE# #UNINDENT# #UNINDENT# if to_pull : #NEWLINE# #INDENT# votes = _Vote . query . filter ( ( _Vote . post_id . in_ ( to_pull ) & ( _Vote . user == self ) ) ) . all ( ) #NEWLINE# for vote in votes : #NEWLINE# #INDENT# self . _vote_cache [ vote . post_id ] = vote . delta #NEWLINE# to_pull . discard ( vote . post_id ) #NEWLINE# #UNINDENT# self . _vote_cache . update ( ( ( x , 0 ) for x in to_pull ) )