#2091 Speedup the Batches logic
Merged 2 years ago by praiskup. Opened 2 years ago by praiskup.
Unknown source speedup-batches  into  main

@@ -0,0 +1,19 @@

+ """

+ Build.batch_id indexed

+ 

+ Revision ID: 9409fc1d5895

+ Revises: 58f7510f0fae

+ Create Date: 2022-02-15 14:38:52.680231

+ """

+ 

+ from alembic import op

+ 

+ 

+ revision = '9409fc1d5895'

+ down_revision = '58f7510f0fae'

+ 

+ def upgrade():

+     op.create_index(op.f('ix_build_batch_id'), 'build', ['batch_id'], unique=False)

+ 

+ def downgrade():

+     op.drop_index(op.f('ix_build_batch_id'), table_name='build')

@@ -4,7 +4,7 @@

  

  import anytree

  

- from coprs import db

+ from coprs import db, cache

  from coprs.helpers import WorkList

  from coprs.models import Batch, Build

  from coprs.exceptions import BadRequest
@@ -52,13 +52,24 @@

          Query for all still not-finished batches, order by id ASC

          """

          batches = set()

-         query = bl.BuildsLogic.processing_builds()

+         query = bl.BuildsLogic.processing_builds().filter(Build.batch_id.isnot(None))

          for build in query.all():

              if build.batch:

                  batches.add(build.batch)

          return batches

  

      @classmethod

+     @cache.memoize(timeout=60)

+     def pending_batch_count_cached(cls):

+         """

+         Return the number of currently processed Batch instances (where at least

+         one build is not yet fully finished).  This is a pretty expensive number

+         and yet we show it on every /stats/ page (and on many others) — that's

+         why we cache it.

+         """

+         return len(cls.pending_batches())

+ 

+     @classmethod

      def pending_batch_trees(cls):

          """

          Get all the currently processing batches, together with all the

@@ -271,7 +271,7 @@

              pending=pending,

              running=running,

              starting=starting,

-             batches=len(BatchesLogic.pending_batches()),

+             batches=BatchesLogic.pending_batch_count_cached(),

          )

  

      @classmethod

@@ -1012,7 +1012,7 @@

  

      chroots = association_proxy("build_chroots", "mock_chroot")

  

-     batch_id = db.Column(db.Integer, db.ForeignKey("batch.id"))

+     batch_id = db.Column(db.Integer, db.ForeignKey("batch.id"), index=True)

      batch = db.relationship("Batch", backref=db.backref("builds"))

  

      module_id = db.Column(db.Integer, db.ForeignKey("module.id"), index=True)

no initial comment

rebased onto f969d421f4fc458e44108c9f3635aa24de0cb532

2 years ago

Build failed. More information on how to proceed and troubleshoot errors available at https://fedoraproject.org/wiki/Zuul-based-ci

2 new commits added

  • frontend: cache the number of currently processed batches
  • frontend: speed-up the models.Batch related routes
2 years ago

Build failed. More information on how to proceed and troubleshoot errors available at https://fedoraproject.org/wiki/Zuul-based-ci

rebased onto 93e51b210c6f85213fa4a92455efc1dea81f309c

2 years ago

Build succeeded.

rebased onto 6b9420b

2 years ago

Commit af7d02f fixes this pull-request

Pull-Request has been merged by praiskup

2 years ago

Commit 6b9420b fixes this pull-request

Pull-Request has been merged by praiskup

2 years ago

Pull-Request has been merged by praiskup

2 years ago

Build succeeded.