File tree Expand file tree Collapse file tree 1 file changed +14
-0
lines changed
Expand file tree Collapse file tree 1 file changed +14
-0
lines changed Original file line number Diff line number Diff line change 22
33# Standard library imports
44import datetime
5+ import hashlib
56import html
67import json
78import logging
@@ -94,6 +95,11 @@ def cache_analytics(
9495 pass
9596
9697
98+ def hash_email (email : str ) -> str :
99+ """Hash email for privacy-safe cache keys."""
100+ return hashlib .sha256 (email .lower ().encode ()).hexdigest ()[:16 ]
101+
102+
97103class ShieldOnException (Exception ):
98104 """Exception raised when shield is on."""
99105
@@ -1050,12 +1056,20 @@ async def get_analytics(
10501056 alert_key = data_store .key ("xon_alert" , user_email )
10511057 alert_record = data_store .get (alert_key )
10521058
1059+ # Always check shieldOn first (privacy - can't cache this)
10531060 if alert_record and alert_record .get ("shieldOn" ):
10541061 raise ShieldOnException ("Shield is on" )
10551062
1063+ # Check cache after shieldOn validation
1064+ cache_key = f"analytics-hierarchy:{ hash_email (user_email )} "
1065+ cached_result = get_cached_analytics (cache_key )
1066+ if cached_result :
1067+ return BreachHierarchyResponse (** cached_result )
1068+
10561069 if xon_record :
10571070 site = str (xon_record ["site" ])
10581071 breach_hierarchy = await get_breach_hierarchy_analytics (site , "" )
1072+ cache_analytics (cache_key , breach_hierarchy )
10591073 return BreachHierarchyResponse (** breach_hierarchy )
10601074
10611075 return JSONResponse (content = None )
You can’t perform that action at this time.
0 commit comments