HUE-2633 [desktop] Optimize checking for orphan docs in sync_documents
HUE-2633 [desktop] Optimize checking for orphan docs in sync_documents

This cuts down the number of required queries from O(N),
where N is the number of Documents, to O(1). Furthermore, it protects
against exceptions, and cleans up old content type records.

todaychi/hue,GitHublong/hue,sanjeevtripurari/hue,xq262144/hue,xiangel/hue,sanjeevtripurari/hue,abhishek-ch/hue,jounex/hue,Peddle/hue,rahul67/hue,Peddle/hue,yoer/hue,epssy/hue,jayceyxc/hue,mapr/hue,cloudera/hue,x303597316/hue,MobinRanjbar/hue,ahmed-mahran/hue,xiangel/hue,jayceyxc/hue,abhishek-ch/hue,hdinsight/hue,jounex/hue,azureplus/hue,rahul67/hue,kawamon/hue,jounex/hue,jjmleiro/hue,fangxingli/hue,kawamon/hue,lumig242/Hue-Integration-with-CDAP,yongshengwang/hue,MobinRanjbar/hue,sanjeevtripurari/hue,jjmleiro/hue,GitHublong/hue,javachengwc/hue,todaychi/hue,hdinsight/hue,cloudera/hue,yongshengwang/hue,cloudera/hue,xq262144/hue,jayceyxc/hue,sanjeevtripurari/hue,yoer/hue,jjmleiro/hue,todaychi/hue,ChenJunor/hue,jjmleiro/hue,fangxingli/hue,jayceyxc/hue,x303597316/hue,xq262144/hue,jjmleiro/hue,xiangel/hue,cloudera/hue,xq262144/hue,vmax-feihu/hue,Peddle/hue,ahmed-mahran/hue,kawamon/hue,javachengwc/hue,cloudera/hue,x303597316/hue,ChenJunor/hue,mapr/hue,yoer/hue,pratikmallya/hue,fangxingli/hue,azureplus/hue,GitHublong/hue,azureplus/hue,vmax-feihu/hue,kawamon/hue,vmax-feihu/hue,cloudera/hue,javachengwc/hue,Peddle/hue,xq262144/hue,azureplus/hue,kawamon/hue,yoer/hue,cloudera/hue,kawamon/hue,xq262144/hue,yongshengwang/hue,mapr/hue,kawamon/hue,jayceyxc/hue,cloudera/hue,ahmed-mahran/hue,pratikmallya/hue,kawamon/hue,ChenJunor/hue,cloudera/hue,pratikmallya/hue,xq262144/hue,jounex/hue,sanjeevtripurari/hue,vmax-feihu/hue,sanjeevtripurari/hue,javachengwc/hue,cloudera/hue,jayceyxc/hue,x303597316/hue,todaychi/hue,GitHublong/hue,yongshengwang/hue,todaychi/hue,todaychi/hue,MobinRanjbar/hue,xiangel/hue,ChenJunor/hue,ahmed-mahran/hue,Peddle/hue,vmax-feihu/hue,rahul67/hue,abhishek-ch/hue,hdinsight/hue,pratikmallya/hue,pratikmallya/hue,kawamon/hue,ahmed-mahran/hue,kawamon/hue,azureplus/hue,jayceyxc/hue,yongshengwang/hue,kawamon/hue,xq262144/hue,xiangel/hue,kawamon/hue,jjmleiro/hue,xiangel/hue,ahmed-mahran/hue,fangxingli/hue,jounex/hue,rahul67/hue,ahmed-mahran/hue,mapr/hue,rahul67/hue,lumig242/Hue-Integration-with-CDAP,todaychi/hue,jjmleiro/hue,rahul67/hue,yongshengwang/hue,ahmed-mahran/hue,abhishek-ch/hue,yoer/hue,MobinRanjbar/hue,azureplus/hue,rahul67/hue,kawamon/hue,yoer/hue,Peddle/hue,cloudera/hue,epssy/hue,vmax-feihu/hue,xiangel/hue,cloudera/hue,epssy/hue,MobinRanjbar/hue,fangxingli/hue,x303597316/hue,lumig242/Hue-Integration-with-CDAP,lumig242/Hue-Integration-with-CDAP,yongshengwang/hue,lumig242/Hue-Integration-with-CDAP,jayceyxc/hue,sanjeevtripurari/hue,javachengwc/hue,cloudera/hue,hdinsight/hue,kawamon/hue,vmax-feihu/hue,GitHublong/hue,MobinRanjbar/hue,x303597316/hue,kawamon/hue,x303597316/hue,cloudera/hue,abhishek-ch/hue,cloudera/hue,rahul67/hue,cloudera/hue,todaychi/hue,javachengwc/hue,pratikmallya/hue,vmax-feihu/hue,x303597316/hue,javachengwc/hue,pratikmallya/hue,hdinsight/hue,cloudera/hue,abhishek-ch/hue,abhishek-ch/hue,MobinRanjbar/hue,xq262144/hue,kawamon/hue,javachengwc/hue,ChenJunor/hue,sanjeevtripurari/hue,hdinsight/hue,ChenJunor/hue,yongshengwang/hue,hdinsight/hue,Peddle/hue,GitHublong/hue,cloudera/hue,ChenJunor/hue,xiangel/hue,jayceyxc/hue,lumig242/Hue-Integration-with-CDAP,GitHublong/hue,yoer/hue,lumig242/Hue-Integration-with-CDAP,jounex/hue,jjmleiro/hue,abhishek-ch/hue,pratikmallya/hue,todaychi/hue,lumig242/Hue-Integration-with-CDAP,fangxingli/hue,epssy/hue,fangxingli/hue,fangxingli/hue,kawamon/hue,lumig242/Hue-Integration-with-CDAP,mapr/hue,azureplus/hue,epssy/hue,ChenJunor/hue,GitHublong/hue,jounex/hue,hdinsight/hue,jjmleiro/hue,mapr/hue,jounex/hue,epssy/hue,kawamon/hue,epssy/hue,MobinRanjbar/hue,Peddle/hue,epssy/hue,mapr/hue,azureplus/hue,Peddle/hue,yoer/hue