mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-04 05:53:43 +00:00 
			
		
		
		
	bulk_create: Refactor bulk_create_streams to not take domain dictionary.
First step in cleaning up populate_db.create_streams and bulk_create.bulk_create_streams. Part of a series of commits to remove Realm.domain from populate_db.
This commit is contained in:
		@@ -66,25 +66,24 @@ def bulk_create_users(realms, users_raw, bot_type=None, tos_version=None):
 | 
			
		||||
                         recipient=recipients_by_email[email]))
 | 
			
		||||
    Subscription.objects.bulk_create(subscriptions_to_create)
 | 
			
		||||
 | 
			
		||||
def bulk_create_streams(realms, stream_dict):
 | 
			
		||||
    # type: (Mapping[text_type, Realm], Dict[text_type, Dict[text_type, Any]]) -> None
 | 
			
		||||
    existing_streams = set((stream.realm.domain, stream.name.lower())
 | 
			
		||||
                           for stream in Stream.objects.select_related().all())
 | 
			
		||||
def bulk_create_streams(realm, stream_dict):
 | 
			
		||||
    # type: (Realm, Dict[text_type, Dict[text_type, Any]]) -> None
 | 
			
		||||
    existing_streams = set(stream.name.lower()
 | 
			
		||||
                           for stream in Stream.objects.select_related().filter(realm=realm))
 | 
			
		||||
    streams_to_create = [] # type: List[Stream]
 | 
			
		||||
    for name, options in stream_dict.items():
 | 
			
		||||
        if (options["domain"], name.lower()) not in existing_streams:
 | 
			
		||||
        if name.lower() not in existing_streams:
 | 
			
		||||
            streams_to_create.append(
 | 
			
		||||
                Stream(
 | 
			
		||||
                    realm=realms[options["domain"]],
 | 
			
		||||
                    name=name, description=options["description"],
 | 
			
		||||
                    realm=realm, name=name, description=options["description"],
 | 
			
		||||
                    invite_only=options["invite_only"]
 | 
			
		||||
                )
 | 
			
		||||
            )
 | 
			
		||||
    Stream.objects.bulk_create(streams_to_create)
 | 
			
		||||
 | 
			
		||||
    recipients_to_create = [] # type: List[Recipient]
 | 
			
		||||
    for stream in Stream.objects.select_related().all():
 | 
			
		||||
        if (stream.realm.domain, stream.name.lower()) not in existing_streams:
 | 
			
		||||
    for stream in Stream.objects.select_related().filter(realm=realm):
 | 
			
		||||
        if stream.name.lower() not in existing_streams:
 | 
			
		||||
            recipients_to_create.append(Recipient(type_id=stream.id,
 | 
			
		||||
                                                  type=Recipient.STREAM))
 | 
			
		||||
    Recipient.objects.bulk_create(recipients_to_create)
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user