mirror of
				https://github.com/zulip/zulip.git
				synced 2025-10-30 11:33:51 +00:00 
			
		
		
		
	cache: Drop the huddle cache.
This cache was only used in one place, which is infrequently called (only when sending messages, or searching explicitly for a list of users) and the overhead of maintaining the cache is not worth trying to avoid the well-indexed lookup of the huddle.
This commit is contained in:
		
				
					committed by
					
						 Tim Abbott
						Tim Abbott
					
				
			
			
				
	
			
			
			
						parent
						
							5591d6f65c
						
					
				
				
					commit
					1f3a53db2d
				
			| @@ -24,7 +24,7 @@ from zerver.lib.cache import ( | ||||
| from zerver.lib.safe_session_cached_db import SessionStore | ||||
| from zerver.lib.sessions import session_engine | ||||
| from zerver.lib.users import get_all_api_keys | ||||
| from zerver.models import Client, Huddle, UserProfile, get_client_cache_key, huddle_hash_cache_key | ||||
| from zerver.models import Client, UserProfile, get_client_cache_key | ||||
|  | ||||
|  | ||||
| def user_cache_items( | ||||
| @@ -43,10 +43,6 @@ def client_cache_items(items_for_remote_cache: Dict[str, Tuple[Client]], client: | ||||
|     items_for_remote_cache[get_client_cache_key(client.name)] = (client,) | ||||
|  | ||||
|  | ||||
| def huddle_cache_items(items_for_remote_cache: Dict[str, Tuple[Huddle]], huddle: Huddle) -> None: | ||||
|     items_for_remote_cache[huddle_hash_cache_key(huddle.huddle_hash)] = (huddle,) | ||||
|  | ||||
|  | ||||
| def session_cache_items( | ||||
|     items_for_remote_cache: Dict[str, Dict[str, object]], session: Session | ||||
| ) -> None: | ||||
| @@ -98,12 +94,6 @@ cache_fillers: Dict[ | ||||
|         3600 * 24 * 7, | ||||
|         10000, | ||||
|     ), | ||||
|     "huddle": ( | ||||
|         lambda: Huddle.objects.select_related("recipient").all(), | ||||
|         huddle_cache_items, | ||||
|         3600 * 24 * 7, | ||||
|         10000, | ||||
|     ), | ||||
|     "session": (lambda: Session.objects.all(), session_cache_items, 3600 * 24 * 7, 10000), | ||||
| } | ||||
|  | ||||
|   | ||||
| @@ -4291,10 +4291,6 @@ def get_huddle_hash(id_list: List[int]) -> str: | ||||
|     return hashlib.sha1(hash_key.encode()).hexdigest() | ||||
|  | ||||
|  | ||||
| def huddle_hash_cache_key(huddle_hash: str) -> str: | ||||
|     return f"huddle_by_hash:{huddle_hash}" | ||||
|  | ||||
|  | ||||
| def get_or_create_huddle(id_list: List[int]) -> Huddle: | ||||
|     """ | ||||
|     Takes a list of user IDs and returns the Huddle object for the | ||||
| @@ -4302,13 +4298,6 @@ def get_or_create_huddle(id_list: List[int]) -> Huddle: | ||||
|     yet exist, it will be transparently created. | ||||
|     """ | ||||
|     huddle_hash = get_huddle_hash(id_list) | ||||
|     return get_or_create_huddle_backend(huddle_hash, id_list) | ||||
|  | ||||
|  | ||||
| @cache_with_key( | ||||
|     lambda huddle_hash, id_list: huddle_hash_cache_key(huddle_hash), timeout=3600 * 24 * 7 | ||||
| ) | ||||
| def get_or_create_huddle_backend(huddle_hash: str, id_list: List[int]) -> Huddle: | ||||
|     with transaction.atomic(): | ||||
|         (huddle, created) = Huddle.objects.get_or_create(huddle_hash=huddle_hash) | ||||
|         if created: | ||||
|   | ||||
		Reference in New Issue
	
	Block a user