def GenerateIndexFromHistory(query_history, all_indexes=None, manual_indexes=None):
 all_keys = datastore_index.IndexDefinitionsToKeys(all_indexes)
 manual_keys = datastore_index.IndexDefinitionsToKeys(manual_indexes)
 indexes = dict(((key, 0) for key in (all_keys - manual_keys)))
 for (query, count) in query_history.iteritems():
  (required, kind, ancestor, props) = datastore_index.CompositeIndexForQuery(query)
  if required:
   props = datastore_index.GetRecommendedIndexProperties(props)
   key = (kind, ancestor, props)
   if (key not in manual_keys):
    if (key in indexes):
     indexes[key] += count
    else:
     indexes[key] = count
 if (not indexes):
  return ''
 res = []
 for ((kind, ancestor, props), count) in sorted(indexes.iteritems()):
  res.append('')
  res.append(datastore_index.IndexYamlForQuery(kind, ancestor, props))
 res.append('')
 return '\n'.join(res)

def GenerateIndexFromHistory ( query_history , all_indexes = None , manual_indexes = None ) : all_keys = datastore_index . IndexDefinitionsToKeys ( all_indexes ) manual_keys = datastore_index . IndexDefinitionsToKeys ( manual_indexes ) indexes = dict ( ( ( key , 0 ) for key in ( all_keys - manual_keys ) ) ) for ( query , count ) in query_history . iteritems ( ) : ( required , kind , ancestor , props ) = datastore_index . CompositeIndexForQuery ( query ) if required : props = datastore_index . GetRecommendedIndexProperties ( props ) key = ( kind , ancestor , props ) if ( key not in manual_keys ) : if ( key in indexes ) : indexes [ key ] += count else : indexes [ key ] = count if ( not indexes ) : return '' res = [ ] for ( ( kind , ancestor , props ) , count ) in sorted ( indexes . iteritems ( ) ) : res . append ( '' ) res . append ( datastore_index . IndexYamlForQuery ( kind , ancestor , props ) ) res . append ( '' ) return '\n' . join ( res )
generate most of the text for index .