More speedups

This change fixes another performance issue where attr.value is dereferenced in a loop (causing hundreds of sql queries) for relation attributes.