Use ORM and reduce the number of sqlite calls to retrieve local groups

Ticket:	#5602