3737NOREPLY_ID_PATTERN = re .compile (r"^(\d+)\+([a-zA-Z0-9-]+)@users\.noreply\.github\.com$" )
3838NOREPLY_USER_PATTERN = re .compile (r"^([a-zA-Z0-9-]+)@users\.noreply\.github\.com$" )
3939
40+ class TTLCache :
41+ def __init__ (self , ttl_seconds = 86400 ):
42+ self .data = {}
43+ self .ttl = ttl_seconds
44+ self .lock = threading .Lock ()
45+
46+ def get (self , key ):
47+ with self .lock :
48+ item = self .data .get (key , None )
49+ if item is None :
50+ return None , False
51+ value , expires_at = item
52+ if time .time () > expires_at :
53+ self .data .pop (key , None )
54+ return None , False
55+ return value , True
56+
57+ def set (self , key , value ):
58+ with self .lock :
59+ self .data [key ] = (value , time .time () + self .ttl )
60+
61+ def cleanup (self ):
62+ with self .lock :
63+ now = time .time ()
64+ keys_to_delete = [k for k , (v , expires_at ) in self .data .items () if now > expires_at ]
65+ for k in keys_to_delete :
66+ del self .data [k ]
67+
68+ github_user_cache = TTLCache (ttl_seconds = 86400 )
69+ def start_cache_cleanup ():
70+ def run ():
71+ while True :
72+ time .sleep (3600 )
73+ github_user_cache .cleanup ()
74+ threading .Thread (target = run , daemon = True ).start ()
75+
76+ start_cache_cleanup ()
4077
4178class GitHub (repository_service_interface .RepositoryService ):
4279 """
@@ -726,8 +763,7 @@ def update_merge_group(self, installation_id, github_repository_id, merge_group_
726763 f"{ fn } - PR: { pull_request .number } , Failed to update change request "
727764 f"of repository { github_repository_id } - returning"
728765 )
729- # XXX
730- # return
766+ return
731767
732768 project_id = repository .get_repository_project_id ()
733769 project = get_project_instance ()
@@ -868,8 +904,7 @@ def update_change_request(self, installation_id, github_repository_id, change_re
868904 f"{ fn } - PR: { pull_request .number } , Failed to update change request "
869905 f"of repository { github_repository_id } - returning"
870906 )
871- # XXX
872- # return
907+ return
873908
874909 # Retrieve project ID from the repository.
875910 project_id = repository .get_repository_project_id ()
@@ -1816,6 +1851,39 @@ def get_co_author_commits(co_author, commit, pr, installation_id):
18161851 email = co_author [1 ].strip ()
18171852 name = co_author [0 ].strip ()
18181853
1854+ # caching starts
1855+ cache_key = (name , email )
1856+ cached_user , hit = github_user_cache .get (cache_key )
1857+
1858+ if hit :
1859+ if cached_user is not None :
1860+ cla .log .debug (f"{ fn } - GitHub user found in cache for name/email: { name } /{ email } : { cached_user } " )
1861+ # Build UserCommitSummary using cached_user
1862+ summary = UserCommitSummary (
1863+ commit .sha ,
1864+ getattr (cached_user , 'id' , None ),
1865+ getattr (cached_user , 'login' , None ),
1866+ name ,
1867+ email ,
1868+ False ,
1869+ False ,
1870+ )
1871+ else :
1872+ cla .log .debug (f"{ fn } - GitHub user found in cache for name/email: { name } /{ email } : (information that this user is missing)" )
1873+ summary = UserCommitSummary (
1874+ commit .sha ,
1875+ None ,
1876+ None ,
1877+ name ,
1878+ email ,
1879+ False ,
1880+ False ,
1881+ )
1882+
1883+ cla .log .debug (f"{ fn } - PR: { pr } , { summary } (from cache)" )
1884+ return summary
1885+ # caching ends
1886+
18191887 # get repository service
18201888 github = cla .utils .get_repository_service ("github" )
18211889 user = None
@@ -1874,13 +1942,13 @@ def get_co_author_commits(co_author, commit, pr, installation_id):
18741942 final_email = email
18751943 try :
18761944 n = user .name
1877- if n and n .strip ():
1945+ if isinstance ( n , str ) and n .strip ():
18781946 final_name = n
18791947 except (AttributeError , GithubException , IncompletableObject ):
18801948 pass
18811949 try :
18821950 e = user .email
1883- if e and e .strip ():
1951+ if isinstance ( e , str ) and e .strip ():
18841952 final_email = e
18851953 except (AttributeError , GithubException , IncompletableObject ):
18861954 pass
@@ -1901,6 +1969,7 @@ def get_co_author_commits(co_author, commit, pr, installation_id):
19011969 )
19021970 cla .log .debug (f"{ fn } - co-author github user details not found : { co_author } " )
19031971
1972+ github_user_cache .set ((name , email ), user )
19041973 return co_author_summary
19051974
19061975
0 commit comments