File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -418,6 +418,7 @@ def search_api(collection):
418418 before = body .get ('before' , inf )
419419 after = body .get ('after' , 0 )
420420 exact = body .get ('exact' , False )
421+ hint = body .get ('hint' , None )
421422
422423 matched_collection = get_collection (collection )
423424
@@ -459,8 +460,20 @@ def match(event) -> bool:
459460
460461 return True
461462
463+ matched_events = []
462464
463- matched_events = [e for e in matched_collection .all_events () if match (e )]
465+ if hint is not None :
466+ # If the client passed a valid hint, search for an easy match first
467+ hinted_event = matched_collection .get_event (hint )
468+ if hinted_event :
469+ hinted_event = get_event_component (hinted_event )
470+ if match (hinted_event ): # Event found and matches predicate. Return immediately
471+ matched_events = [hinted_event ]
472+ else :
473+ logging .warning (f"Caller hinted with event: { hint } , but didn't match search predicate" )
474+
475+ if not matched_events :
476+ matched_events = [e for e in matched_collection .all_events () if match (e )]
464477
465478 def compare_events (left , right ):
466479 def cmp (field : str ) -> bool :
Original file line number Diff line number Diff line change @@ -50,6 +50,9 @@ def is_event_visible(self, event) -> bool:
5050
5151
5252 def get_event_impl (self , name : str ):
53+ if '/' in name or '<' in name or '>' in name or '"' in name or "'" in name or '?' in name or '&' in name :
54+ raise SuspiciousRequest ('Suspicous event name: ' + name )
55+
5356 response = requests .get (self .url + name , auth = self .auth )
5457 if response .status_code == 404 :
5558 return None
@@ -60,9 +63,6 @@ def get_event_impl(self, name: str):
6063
6164
6265 def get_event (self , name : str ):
63- if '/' in name or '<' in name or '>' in name or '"' in name or "'" in name :
64- raise SuspiciousRequest ('Suspicous event name: ' + name )
65-
6666 if self .uid_only :
6767 # Special case for calendar providers that don't support individual event queries
6868 matched_events = [e for e in self .all_events () if e .get ('uid' ) == name ]
You can’t perform that action at this time.
0 commit comments