Skip to content

Commit 475e1ae

Browse files
committed
db: add indexes, optimize status fetching time
1 parent 9cc13c8 commit 475e1ae

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

database.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,16 @@ def __init__(self, context):
369369

370370
Base.metadata.create_all(self.engine)
371371

372+
# TODO: use DB migrations
373+
try:
374+
sa.Index('pullrequest_status', Pullrequest.status).create(self.engine)
375+
sa.Index('status_active', Status.active).create(self.engine)
376+
sa.Index('status_prid', Status.prid).create(self.engine)
377+
sa.Index('status_bid', Status.bid).create(self.engine)
378+
except:
379+
# already exists
380+
pass
381+
372382
def _createSession(self):
373383
# :rtype sqlalchemy.orm.session.Session
374384
return self.Session()
@@ -507,7 +517,9 @@ def thd(session):
507517

508518
def getAllActiveStatuses(self):
509519
def thd(session):
510-
ss = session.query(Status).filter(Status.active == True).all()
520+
ss = session.query(Status).filter(Status.active == True)\
521+
.join(Pullrequest).filter(Pullrequest.status >= 0)\
522+
.all()
511523
return ss
512524
return self.db.asyncRun(thd)
513525

0 commit comments

Comments
 (0)