Move filter logic to DB