get rid of many n+1 queries when generating an index