only do database query once