mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-03 21:43:21 +00:00 
			
		
		
		
	analytics: Pass subgroup=None to improve indexing.
Because the main indexes on end_time either don't include realm_id or do include subgroup, passing an explicit subgroup=None for single-realm queries to read CountStats that don't use the subgroups feature greatly improves the query plans.
This commit is contained in:
		
				
					committed by
					
						
						Alex Vandiver
					
				
			
			
				
	
			
			
			
						parent
						
							9c8cc8c333
						
					
				
				
					commit
					1ff14fd0f1
				
			@@ -67,7 +67,13 @@ def get_active_realm_ids() -> QuerySet[RealmCount, int]:
 | 
			
		||||
    """
 | 
			
		||||
    date = timezone_now() - timedelta(days=2)
 | 
			
		||||
    return (
 | 
			
		||||
        RealmCount.objects.filter(end_time__gte=date, property="1day_actives::day", value__gt=0)
 | 
			
		||||
        RealmCount.objects.filter(
 | 
			
		||||
            end_time__gte=date,
 | 
			
		||||
            property="1day_actives::day",
 | 
			
		||||
            # Filtering on subgroup is important to ensure we use the good indexes.
 | 
			
		||||
            subgroup=None,
 | 
			
		||||
            value__gt=0,
 | 
			
		||||
        )
 | 
			
		||||
        .distinct("realm_id")
 | 
			
		||||
        .values_list("realm_id", flat=True)
 | 
			
		||||
    )
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user