Boost courses semester filter block performance by using db_select().

#5437 
The change gives 33% performance boost when testing performance of `economics/courses` page.
Before:
Time per request:       2989.085 [ms] (mean)
After:
Time per request:       1993.918 [ms] (mean)