def GetCounts(self,
                  tag_display_type,
                  tag_service_id,
                  file_service_id,
                  tag_ids,
                  include_current,
                  include_pending,
                  domain_is_cross_referenced=True,
                  zero_count_ok=False,
                  job_key=None,
                  tag_ids_table_name=None):

        if len(tag_ids) == 0:

            return {}

        if tag_service_id == self.modules_services.combined_tag_service_id and file_service_id == self.modules_services.combined_file_service_id:

            ids_to_count = {}

            return ids_to_count

        if tag_service_id == self.modules_services.combined_tag_service_id:

            search_tag_service_ids = self.modules_services.GetServiceIds(
                HC.REAL_TAG_SERVICES)

        else:

            search_tag_service_ids = [tag_service_id]

        cache_results = []

        if len(tag_ids) > 1:

            if tag_ids_table_name is None:

                with self._MakeTemporaryIntegerTable(
                        tag_ids, 'tag_id') as temp_tag_id_table_name:

                    for search_tag_service_id in search_tag_service_ids:

                        if job_key is not None and job_key.IsCancelled():

                            return {}

                        cache_results.extend(
                            self.GetCountsForTags(tag_display_type,
                                                  file_service_id,
                                                  search_tag_service_id,
                                                  temp_tag_id_table_name))

            else:

                for search_tag_service_id in search_tag_service_ids:

                    if job_key is not None and job_key.IsCancelled():

                        return {}

                    cache_results.extend(
                        self.GetCountsForTags(tag_display_type,
                                              file_service_id,
                                              search_tag_service_id,
                                              tag_ids_table_name))

        else:

            (tag_id, ) = tag_ids

            for search_tag_service_id in search_tag_service_ids:

                cache_results.extend(
                    self.GetCountsForTag(tag_display_type, file_service_id,
                                         search_tag_service_id, tag_id))

        #

        ids_to_count = {}

        for (tag_id, current_count, pending_count) in cache_results:

            if not include_current:

                current_count = 0

            if not include_pending:

                pending_count = 0

            if current_count == 0 and pending_count == 0 and not zero_count_ok:

                continue

            current_max = current_count
            pending_max = pending_count

            if domain_is_cross_referenced:

                # file counts are perfectly accurate

                current_min = current_count
                pending_min = pending_count

            else:

                # for instance this is a search for 'my files' deleted files, but we are searching on 'all deleted files' domain

                current_min = 0
                pending_min = 0

            if tag_id in ids_to_count:

                (existing_current_min, existing_current_max,
                 existing_pending_min,
                 existing_pending_max) = ids_to_count[tag_id]

                (current_min, current_max) = ClientData.MergeCounts(
                    existing_current_min, existing_current_max, current_min,
                    current_max)
                (pending_min, pending_max) = ClientData.MergeCounts(
                    existing_pending_min, existing_pending_max, pending_min,
                    pending_max)

            ids_to_count[tag_id] = (current_min, current_max, pending_min,
                                    pending_max)

        if zero_count_ok:

            for tag_id in tag_ids:

                if tag_id not in ids_to_count:

                    ids_to_count[tag_id] = (0, 0, 0, 0)

        return ids_to_count
 def GetCounts( self, tag_display_type, tag_service_id, file_service_id, tag_ids, include_current, include_pending, zero_count_ok = False, job_key = None, tag_ids_table_name = None ):
     
     if len( tag_ids ) == 0:
         
         return {}
         
     
     if tag_service_id == self.modules_services.combined_tag_service_id and file_service_id == self.modules_services.combined_file_service_id:
         
         ids_to_count = {}
         
         return ids_to_count
         
     
     if tag_service_id == self.modules_services.combined_tag_service_id:
         
         search_tag_service_ids = self.modules_services.GetServiceIds( HC.REAL_TAG_SERVICES )
         
     else:
         
         search_tag_service_ids = [ tag_service_id ]
         
     
     cache_results = []
     
     if len( tag_ids ) > 1:
         
         if tag_ids_table_name is None:
             
             with self._MakeTemporaryIntegerTable( tag_ids, 'tag_id' ) as temp_tag_id_table_name:
                 
                 for search_tag_service_id in search_tag_service_ids:
                     
                     if job_key is not None and job_key.IsCancelled():
                         
                         return {}
                         
                     
                     cache_results.extend( self.GetCountsForTags( tag_display_type, file_service_id, search_tag_service_id, temp_tag_id_table_name ) )
                     
                 
             
         else:
             
             for search_tag_service_id in search_tag_service_ids:
                 
                 if job_key is not None and job_key.IsCancelled():
                     
                     return {}
                     
                 
                 cache_results.extend( self.GetCountsForTags( tag_display_type, file_service_id, search_tag_service_id, tag_ids_table_name ) )
                 
             
         
     else:
         
         ( tag_id, ) = tag_ids
         
         for search_tag_service_id in search_tag_service_ids:
             
             cache_results.extend( self.GetCountsForTag( tag_display_type, file_service_id, search_tag_service_id, tag_id ) )
             
         
     
     #
     
     ids_to_count = {}
     
     for ( tag_id, current_count, pending_count ) in cache_results:
         
         if not include_current:
             
             current_count = 0
             
         
         if not include_pending:
             
             pending_count = 0
             
         
         if current_count == 0 and pending_count == 0 and not zero_count_ok:
             
             continue
             
         
         if tag_id in ids_to_count:
             
             ( current_min, current_max, pending_min, pending_max ) = ids_to_count[ tag_id ]
             
             ( current_min, current_max ) = ClientData.MergeCounts( current_min, current_max, current_count, None )
             ( pending_min, pending_max ) = ClientData.MergeCounts( pending_min, pending_max, pending_count, None )
             
         else:
             
             ( current_min, current_max, pending_min, pending_max ) = ( current_count, None, pending_count, None )
             
         
         ids_to_count[ tag_id ] = ( current_min, current_max, pending_min, pending_max )
         
     
     if zero_count_ok:
         
         for tag_id in tag_ids:
             
             if tag_id not in ids_to_count:
                 
                 ids_to_count[ tag_id ] = ( 0, None, 0, None )
                 
             
         
     
     return ids_to_count