#NEWLINE# def get_klass_info( klass , max_depth = 0 , cur_depth = 0 , requested = None , only_load = None , local_only = False ) : #NEWLINE# #INDENT# '\n    Helper function that recursively returns an information for a klass, to be\n    used in get_cached_row.  It exists just to compute this information only\n    once for entire queryset. Otherwise it would be computed for each row, which\n    leads to poor perfomance on large querysets.\n\n    Arguments:\n     * klass - the class to retrieve (and instantiate)\n     * max_depth - the maximum depth to which a select_related()\n       relationship should be explored.\n     * cur_depth - the current depth in the select_related() tree.\n       Used in recursive calls to determin if we should dig deeper.\n     * requested - A dictionary describing the select_related() tree\n       that is to be retrieved. keys are field names; values are\n       dictionaries describing the keys on that related object that\n       are themselves to be select_related().\n     * only_load - if the query has had only() or defer() applied,\n       this is the list of field names that will be returned. If None,\n       the full field list for `klass` can be assumed.\n     * local_only - Only populate local fields. This is used when\n       following reverse select-related relations\n    ' #NEWLINE# if ( max_depth and ( requested is None ) and ( cur_depth > max_depth ) ) : #NEWLINE# #INDENT# return None #NEWLINE# #UNINDENT# if only_load : #NEWLINE# #INDENT# load_fields = ( only_load . get ( klass ) or set ( ) ) #NEWLINE# for parent in klass . _meta . get_parent_list ( ) : #NEWLINE# #INDENT# fields = only_load . get ( parent ) #NEWLINE# if fields : #NEWLINE# #INDENT# load_fields . update ( fields ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# load_fields = None #NEWLINE# #UNINDENT# if load_fields : #NEWLINE# #INDENT# skip = set ( ) #NEWLINE# init_list = [ ] #NEWLINE# for ( field , model ) in klass . _meta . get_fields_with_model ( ) : #NEWLINE# #INDENT# if ( field . name not in load_fields ) : #NEWLINE# #INDENT# skip . add ( field . attname ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( local_only and ( model is not None ) ) : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# init_list . append ( field . attname ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# field_count = len ( init_list ) #NEWLINE# if skip : #NEWLINE# #INDENT# klass = deferred_class_factory ( klass , skip ) #NEWLINE# field_names = init_list #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# field_names = ( ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if ( local_only and ( len ( klass . _meta . local_fields ) != len ( klass . _meta . fields ) ) ) : #NEWLINE# #INDENT# field_count = len ( klass . _meta . local_fields ) #NEWLINE# field_names = [ f . attname for f in klass . _meta . local_fields ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# field_count = len ( klass . _meta . fields ) #NEWLINE# field_names = ( ) #NEWLINE# #UNINDENT# #UNINDENT# restricted = ( requested is not None ) #NEWLINE# related_fields = [ ] #NEWLINE# for f in klass . _meta . fields : #NEWLINE# #INDENT# if select_related_descend ( f , restricted , requested , load_fields ) : #NEWLINE# #INDENT# if restricted : #NEWLINE# #INDENT# next = requested [ f . name ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# next = None #NEWLINE# #UNINDENT# klass_info = get_klass_info ( f . rel . to , max_depth = max_depth , cur_depth = ( cur_depth + 1 ) , requested = next , only_load = only_load ) #NEWLINE# related_fields . append ( ( f , klass_info ) ) #NEWLINE# #UNINDENT# #UNINDENT# reverse_related_fields = [ ] #NEWLINE# if restricted : #NEWLINE# #INDENT# for o in klass . _meta . get_all_related_objects ( ) : #NEWLINE# #INDENT# if ( o . field . unique and select_related_descend ( o . field , restricted , requested , only_load . get ( o . model ) , reverse = True ) ) : #NEWLINE# #INDENT# next = requested [ o . field . related_query_name ( ) ] #NEWLINE# klass_info = get_klass_info ( o . model , max_depth = max_depth , cur_depth = ( cur_depth + 1 ) , requested = next , only_load = only_load , local_only = True ) #NEWLINE# reverse_related_fields . append ( ( o . field , klass_info ) ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# if field_names : #NEWLINE# #INDENT# pk_idx = field_names . index ( klass . _meta . pk . attname ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# pk_idx = klass . _meta . pk_index ( ) #NEWLINE# #UNINDENT# return ( klass , field_names , field_count , related_fields , reverse_related_fields , pk_idx )