Optimize queries for PosgreSQL. Refactoring sync, ams, news sections.