Changeset - ad374c171656
[Not reviewed]
default
0 1 0
Mads Kiilerich - 11 years ago 2015-01-06 00:54:36
madski@unity3d.com
comments: introduce lazy join of ChangesetStatus on ChangesetComment

99% of all uses of ChangesetComment will also need the optional corresponding
ChangesetStatus (if any) on the status_change relationship. Fetching it on
demand gives a lot of roundtrips and might be slow ... but adding explicit bulk
queries everywhere do not seem feasible. Adding lazy=joined in the data model
seems like the best solution.

Loading a pull request with 10 comments on a slow repo goes from 3.5 s to
2.7 s.
1 file changed with 4 insertions and 1 deletions:
0 comments (0 inline, 0 general)
kallithea/model/db.py
Show inline comments
 
@@ -2149,7 +2149,10 @@ class ChangesetComment(Base, BaseModel):
 

	
 
    author = relationship('User', lazy='joined')
 
    repo = relationship('Repository')
 
    status_change = relationship('ChangesetStatus', cascade="all, delete-orphan")
 
    # status_change is frequently used directly in templates - make it a lazy
 
    # join to avoid fetching each related ChangesetStatus on demand.
 
    # There will only be one ChangesetStatus referencing each comment so the join will not explode.
 
    status_change = relationship('ChangesetStatus', cascade="all, delete-orphan", lazy='joined')
 
    pull_request = relationship('PullRequest')
 

	
 
    @classmethod
0 comments (0 inline, 0 general)