nodes: 0, module; 1, function_definition; 2, function_name:refresh_identities; 3, parameters; 4, block; 5, identifier:enrich_backend; 6, default_parameter; 7, default_parameter; 8, expression_statement; 9, function_definition; 10, expression_statement; 11, expression_statement; 12, expression_statement; 13, expression_statement; 14, if_statement; 15, expression_statement; 16, identifier:author_field; 17, None; 18, identifier:author_values; 19, None; 20, comment:"""Refresh identities in enriched index.
  
      Retrieve items from the enriched index corresponding to enrich_backend,
      and update their identities information, with fresh data from the
      SortingHat database.
  
      Instead of the whole index, only items matching the filter_author
      filter are fitered, if that parameters is not None.
  
      :param enrich_backend: enriched backend to update
      :param  author_field: field to match items authored by a user
      :param  author_values: values of the authored field to match items
      """; 21, function_name:update_items; 22, parameters; 23, block; 24, call; 25, assignment; 26, assignment; 27, call; 28, comparison_operator:author_field is None; 29, comment:# No filter, update all items; 30, block; 31, else_clause; 32, call; 33, identifier:new_filter_author; 34, for_statement; 35, attribute; 36, argument_list; 37, identifier:total; 38, integer:0; 39, identifier:max_ids; 40, attribute; 41, attribute; 42, argument_list; 43, identifier:author_field; 44, None; 45, for_statement; 46, block; 47, attribute; 48, argument_list; 49, identifier:eitem; 50, call; 51, block; 52, identifier:logger; 53, identifier:debug; 54, string:"Refreshing identities fields from %s"; 55, call; 56, attribute; 57, identifier:max_items_clause; 58, identifier:logger; 59, identifier:debug; 60, string; 61, identifier:item; 62, call; 63, block; 64, expression_statement; 65, for_statement; 66, if_statement; 67, identifier:logger; 68, identifier:info; 69, string:"Total eitems refreshed for identities fields %i"; 70, identifier:total; 71, attribute; 72, argument_list; 73, expression_statement; 74, try_statement; 75, expression_statement; 76, expression_statement; 77, expression_statement; 78, attribute; 79, argument_list; 80, identifier:enrich_backend; 81, identifier:elastic; 82, string_content:Refreshing identities; 83, identifier:update_items; 84, argument_list; 85, expression_statement; 86, expression_statement; 87, assignment; 88, identifier:author_value; 89, identifier:author_values; 90, block; 91, comparison_operator:len(to_refresh) > 0; 92, block; 93, identifier:enrich_backend; 94, identifier:fetch; 95, identifier:new_filter_author; 96, assignment; 97, block; 98, except_clause; 99, assignment; 100, call; 101, yield; 102, attribute; 103, identifier:anonymize_url; 104, attribute; 105, None; 106, yield; 107, augmented_assignment; 108, identifier:to_refresh; 109, list; 110, expression_statement; 111, if_statement; 112, call; 113, integer:0; 114, expression_statement; 115, for_statement; 116, identifier:roles; 117, None; 118, expression_statement; 119, identifier:AttributeError; 120, block; 121, identifier:new_identities; 122, call; 123, attribute; 124, argument_list; 125, identifier:eitem; 126, identifier:enrich_backend; 127, identifier:elastic; 128, attribute; 129, identifier:index_url; 130, identifier:item; 131, identifier:total; 132, integer:1; 133, call; 134, comparison_operator:len(to_refresh) > max_ids; 135, block; 136, identifier:len; 137, argument_list; 138, assignment; 139, identifier:item; 140, call; 141, block; 142, assignment; 143, pass_statement; 144, attribute; 145, argument_list; 146, identifier:eitem; 147, identifier:update; 148, identifier:new_identities; 149, identifier:enrich_backend; 150, identifier:elastic; 151, attribute; 152, argument_list; 153, call; 154, identifier:max_ids; 155, expression_statement; 156, for_statement; 157, expression_statement; 158, identifier:to_refresh; 159, identifier:filter_author; 160, dictionary; 161, identifier:update_items; 162, argument_list; 163, expression_statement; 164, expression_statement; 165, identifier:roles; 166, attribute; 167, identifier:enrich_backend; 168, identifier:get_item_sh_from_id; 169, identifier:eitem; 170, identifier:roles; 171, identifier:to_refresh; 172, identifier:append; 173, identifier:author_value; 174, identifier:len; 175, argument_list; 176, assignment; 177, identifier:item; 178, call; 179, block; 180, assignment; 181, pair; 182, pair; 183, identifier:filter_author; 184, yield; 185, augmented_assignment; 186, identifier:enrich_backend; 187, identifier:roles; 188, identifier:to_refresh; 189, identifier:filter_author; 190, dictionary; 191, identifier:update_items; 192, argument_list; 193, expression_statement; 194, expression_statement; 195, identifier:to_refresh; 196, list; 197, string:"name"; 198, identifier:author_field; 199, string:"value"; 200, identifier:to_refresh; 201, identifier:item; 202, identifier:total; 203, integer:1; 204, pair; 205, pair; 206, identifier:filter_author; 207, yield; 208, augmented_assignment; 209, string:"name"; 210, identifier:author_field; 211, string:"value"; 212, identifier:to_refresh; 213, identifier:item; 214, identifier:total; 215, integer:1
code: def refresh_identities(enrich_backend, author_field=None, author_values=None):
      """Refresh identities in enriched index.
  
      Retrieve items from the enriched index corresponding to enrich_backend,
      and update their identities information, with fresh data from the
      SortingHat database.
  
      Instead of the whole index, only items matching the filter_author
      filter are fitered, if that parameters is not None.
  
      :param enrich_backend: enriched backend to update
      :param  author_field: field to match items authored by a user
      :param  author_values: values of the authored field to match items
      """
  
      def update_items(new_filter_author):
  
          for eitem in enrich_backend.fetch(new_filter_author):
              roles = None
              try:
                  roles = enrich_backend.roles
              except AttributeError:
                  pass
              new_identities = enrich_backend.get_item_sh_from_id(eitem, roles)
              eitem.update(new_identities)
              yield eitem
  
      logger.debug("Refreshing identities fields from %s",
                   enrich_backend.elastic.anonymize_url(enrich_backend.elastic.index_url))
  
      total = 0
  
      max_ids = enrich_backend.elastic.max_items_clause
      logger.debug('Refreshing identities')
  
      if author_field is None:
          # No filter, update all items
          for item in update_items(None):
              yield item
              total += 1
      else:
          to_refresh = []
          for author_value in author_values:
              to_refresh.append(author_value)
  
              if len(to_refresh) > max_ids:
                  filter_author = {"name": author_field,
                                   "value": to_refresh}
  
                  for item in update_items(filter_author):
                      yield item
                      total += 1
  
                  to_refresh = []
  
          if len(to_refresh) > 0:
              filter_author = {"name": author_field,
                               "value": to_refresh}
  
              for item in update_items(filter_author):
                  yield item
                  total += 1
  
      logger.info("Total eitems refreshed for identities fields %i", total)