Now you get from usage_type from database all time, so you ask database for the same value many times. Better when you take it one time and pass to the function.