mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-04 05:53:43 +00:00 
			
		
		
		
	models: Add a partial index on unread DMs.
This helps the find_first_unread_anchor call for DMs with a user.
This commit is contained in:
		
				
					committed by
					
						
						Tim Abbott
					
				
			
			
				
	
			
			
			
						parent
						
							04f7dd998b
						
					
				
				
					commit
					83acf70d0f
				
			@@ -0,0 +1,22 @@
 | 
			
		||||
from django.contrib.postgres.operations import AddIndexConcurrently
 | 
			
		||||
from django.db import migrations, models
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class Migration(migrations.Migration):
 | 
			
		||||
    atomic = False
 | 
			
		||||
    dependencies = [
 | 
			
		||||
        ("zerver", "0741_pushdevice_zerver_pushdevice_user_bouncer_device_id_idx"),
 | 
			
		||||
    ]
 | 
			
		||||
 | 
			
		||||
    operations = [
 | 
			
		||||
        AddIndexConcurrently(
 | 
			
		||||
            model_name="usermessage",
 | 
			
		||||
            index=models.Index(
 | 
			
		||||
                models.F("user_profile"),
 | 
			
		||||
                models.F("message"),
 | 
			
		||||
                condition=models.Q(("flags__andnz", 2048), ("flags__andz", 1)),
 | 
			
		||||
                name="zerver_usermessage_is_private_unread_message_id",
 | 
			
		||||
            ),
 | 
			
		||||
        ),
 | 
			
		||||
        migrations.RunSQL("ANALYZE zerver_usermessage"),
 | 
			
		||||
    ]
 | 
			
		||||
@@ -636,6 +636,15 @@ class UserMessage(AbstractUserMessage):
 | 
			
		||||
                condition=Q(flags__andnz=AbstractUserMessage.flags.is_private.mask),
 | 
			
		||||
                name="zerver_usermessage_is_private_message_id",
 | 
			
		||||
            ),
 | 
			
		||||
            models.Index(
 | 
			
		||||
                "user_profile",
 | 
			
		||||
                "message",
 | 
			
		||||
                condition=(
 | 
			
		||||
                    Q(flags__andnz=AbstractUserMessage.flags.is_private.mask)
 | 
			
		||||
                    & Q(flags__andz=AbstractUserMessage.flags.read.mask)
 | 
			
		||||
                ),
 | 
			
		||||
                name="zerver_usermessage_is_private_unread_message_id",
 | 
			
		||||
            ),
 | 
			
		||||
            models.Index(
 | 
			
		||||
                "user_profile",
 | 
			
		||||
                "message",
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user