Skip to content

Commit

Permalink
[frontend] speed up querying for recent builds
Browse files Browse the repository at this point in the history
  • Loading branch information
FrostyX committed Sep 27, 2016
1 parent 468e2d1 commit 6c860af
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 4 deletions.
@@ -0,0 +1,26 @@
"""add index to build_chroot.ended_on column
Revision ID: 3a9905ed8ffd
Revises: 3341bf554454
Create Date: 2016-09-27 11:57:50.075139
"""

# revision identifiers, used by Alembic.
revision = '3a9905ed8ffd'
down_revision = '3341bf554454'

from alembic import op
import sqlalchemy as sa


def upgrade():
### commands auto generated by Alembic - please adjust! ###
op.create_index(op.f('ix_build_chroot_ended_on'), 'build_chroot', ['ended_on'], unique=False)
### end Alembic commands ###


def downgrade():
### commands auto generated by Alembic - please adjust! ###
op.drop_index('ix_build_chroot_ended_on', table_name='build_chroot')
### end Alembic commands ###
9 changes: 6 additions & 3 deletions frontend/coprs_frontend/coprs/logic/builds_logic.py
Expand Up @@ -57,9 +57,12 @@ def get_recent_tasks(cls, user=None, limit=None):
if not limit:
limit = 100

query = models.Build.query \
.join(models.BuildChroot).filter(models.BuildChroot.ended_on.isnot(None)) \
.order_by(models.BuildChroot.ended_on.desc())
query = models.Build.query.join(
models.BuildChroot.query\
.filter(models.BuildChroot.ended_on.isnot(None))\
.order_by(models.BuildChroot.ended_on.desc())\
.limit(limit).subquery()
)

if user is not None:
query = query.filter(models.Build.user_id == user.id)
Expand Down
2 changes: 1 addition & 1 deletion frontend/coprs_frontend/coprs/models.py
Expand Up @@ -885,7 +885,7 @@ class BuildChroot(db.Model, helpers.Serializer):
status = db.Column(db.Integer, default=StatusEnum("importing"))

started_on = db.Column(db.Integer)
ended_on = db.Column(db.Integer)
ended_on = db.Column(db.Integer, index=True)

last_deferred = db.Column(db.Integer)

Expand Down

0 comments on commit 6c860af

Please sign in to comment.