Mercurial > kallithea
changeset 4752:ad374c171656
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.
author | Mads Kiilerich <madski@unity3d.com> |
---|---|
date | Tue, 06 Jan 2015 00:54:36 +0100 |
parents | d8ad71e7b90d |
children | 30a1b3fdd713 |
files | kallithea/model/db.py |
diffstat | 1 files changed, 4 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/kallithea/model/db.py Tue Jan 06 00:54:36 2015 +0100 +++ b/kallithea/model/db.py Tue Jan 06 00:54:36 2015 +0100 @@ -2149,7 +2149,10 @@ 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