66from sentry_sdk import get_current_span
77from shared .config import get_config
88
9- from database .models .core import Commit , Owner , Repository
9+ from database .models .core import Owner , Repository
1010
1111log = logging .getLogger ("log_context" )
1212
@@ -28,6 +28,11 @@ class LogContext:
2828 repo_name : str | None = None
2929 repo_id : int | None = None
3030 commit_sha : str | None = None
31+
32+ # TODO: begin populating this again or remove it
33+ # we can populate this again if we reduce query load by passing the Commit,
34+ # Owner, and Repository models we use to populate the log context into the
35+ # various task implementations so they don't fetch the same models again
3136 commit_id : int | None = None
3237
3338 checkpoints_data : dict = field (default_factory = lambda : {})
@@ -58,48 +63,13 @@ def populate_from_sqlalchemy(self, dbsession):
5863 return
5964
6065 try :
61- can_identify_commit = self .commit_id is not None or (
62- self .commit_sha is not None and self .repo_id is not None
63- )
64-
65- # commit_id or (commit_sha + repo_id) is enough to get everything else
66- if can_identify_commit :
67- query = (
68- dbsession .query (
69- Commit .id_ ,
70- Commit .commitid ,
71- Repository .repoid ,
72- Repository .name ,
73- Owner .ownerid ,
74- Owner .username ,
75- Owner .service ,
76- Owner .plan ,
77- )
78- .join (Commit .repository )
79- .join (Repository .owner )
80- )
81-
82- if self .commit_id is not None :
83- query = query .filter (Commit .id_ == self .commit_id )
84- else :
85- query = query .filter (
86- Commit .commitid == self .commit_sha ,
87- Commit .repoid == self .repo_id ,
88- )
89-
90- (
91- self .commit_id ,
92- self .commit_sha ,
93- self .repo_id ,
94- self .repo_name ,
95- self .owner_id ,
96- self .owner_username ,
97- self .owner_service ,
98- self .owner_plan ,
99- ) = query .first ()
66+ # - commit_id (or commit_sha + repo_id) is enough to get everything else
67+ # - however, this slams the commit table and we rarely really need the
68+ # DB PK for a commit, so we don't do this.
69+ # - repo_id is enough to get repo and owner
70+ # - owner_id is just enough to get owner
10071
101- # repo_id is enough to get repo and owner
102- elif self .repo_id :
72+ if self .repo_id :
10373 query = (
10474 dbsession .query (
10575 Repository .name ,
@@ -120,7 +90,6 @@ def populate_from_sqlalchemy(self, dbsession):
12090 self .owner_plan ,
12191 ) = query .first ()
12292
123- # owner_id is just enough for owner
12493 elif self .owner_id :
12594 query = dbsession .query (
12695 Owner .username , Owner .service , Owner .plan
0 commit comments