Browse Source

Merge "Speed up loading a change with eager loading"

changes/91/391991/1
Jenkins 5 years ago
committed by Gerrit Code Review
parent
commit
f4315cbb34
2 changed files with 7 additions and 4 deletions
  1. +6
    -3
      gertty/db.py
  2. +1
    -1
      gertty/view/change.py

+ 6
- 3
gertty/db.py View File

@ -24,7 +24,7 @@ import six
import sqlalchemy
from sqlalchemy import create_engine, MetaData, Table, Column, Integer, String, Boolean, DateTime, Text, UniqueConstraint
from sqlalchemy.schema import ForeignKey
from sqlalchemy.orm import mapper, sessionmaker, relationship, scoped_session
from sqlalchemy.orm import mapper, sessionmaker, relationship, scoped_session, joinedload
from sqlalchemy.orm.session import Session
from sqlalchemy.sql import exists
from sqlalchemy.sql.expression import and_
@ -815,9 +815,12 @@ class DatabaseSession(object):
except sqlalchemy.orm.exc.NoResultFound:
return self.createSyncQuery(name)
def getChange(self, key):
def getChange(self, key, lazy=True):
query = self.session().query(Change).filter_by(key=key)
if not lazy:
query = query.options(joinedload(Change.revisions).joinedload(Revision.files).joinedload(File.comments))
try:
return self.session().query(Change).filter_by(key=key).one()
return query.one()
except sqlalchemy.orm.exc.NoResultFound:
return None


+ 1
- 1
gertty/view/change.py View File

@ -618,7 +618,7 @@ class ChangeView(urwid.WidgetWrap):
def refresh(self):
with self.app.db.getSession() as session:
change = session.getChange(self.change_key)
change = session.getChange(self.change_key, lazy=False)
# When we first open the change, update its last_seen
# time.
if not self.marked_seen:


Loading…
Cancel
Save