@transaction_atomic_with_retry()<EOL><INDENT>def upsert_entity_kinds(self, entity_kinds):<DEDENT>
<EOL>unchanged_entity_kinds = {}<EOL>if entity_kinds:<EOL><INDENT>unchanged_entity_kinds = {<EOL>(entity_kind.name, entity_kind.display_name): entity_kind<EOL>for entity_kind in EntityKind.all_objects.extra(<EOL>where=['<STR_LIT>'],<EOL>params=[tuple(<EOL>(entity_kind.name, entity_kind.display_name)<EOL>for entity_kind in entity_kinds<EOL>)]<EOL>)<EOL>}<EOL><DEDENT>changed_entity_kinds = [<EOL>entity_kind<EOL>for entity_kind in entity_kinds<EOL>if (entity_kind.name, entity_kind.display_name) not in unchanged_entity_kinds<EOL>]<EOL>upserted_enitity_kinds = []<EOL>if changed_entity_kinds:<EOL><INDENT>list(EntityKind.all_objects.all().select_for_update().values_list('<STR_LIT:id>', flat=True))<EOL>upserted_enitity_kinds = manager_utils.bulk_upsert(<EOL>queryset=EntityKind.all_objects.filter(<EOL>name__in=[entity_kind.name for entity_kind in changed_entity_kinds]<EOL>),<EOL>model_objs=changed_entity_kinds,<EOL>unique_fields=['<STR_LIT:name>'],<EOL>update_fields=['<STR_LIT>'],<EOL>return_upserts=True<EOL>)<EOL><DEDENT>return upserted_enitity_kinds + list(unchanged_entity_kinds.values())<EOL>
Given a list of entity kinds ensure they are synced properly to the database.
This will ensure that only unchanged entity kinds are synced and will still return all
updated entity kinds

:param entity_kinds: The list of entity kinds to sync