Optimize query when inserting and removing favorite project fields