Skip to content

Commit

Permalink
[#65] speed up loading branch results page
Browse files Browse the repository at this point in the history
  • Loading branch information
godfryd committed Dec 17, 2020
1 parent b249814 commit 1e0b1bc
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
8 changes: 7 additions & 1 deletion server/kraken/server/execution.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,9 +368,15 @@ def get_flows(branch_id, kind, start=0, limit=10, middle=None):
else:
kind = 0
q = Flow.query.filter_by(branch_id=branch_id, kind=kind)
q = q.options(joinedload('branch'),
joinedload('branch.project'),
joinedload('branch.stages'),
joinedload('artifacts_files'),
joinedload('runs'),
joinedload('runs.artifacts_files'))
if middle is None:
q = q.order_by(desc(Flow.created))
total = q.count()
q = q.order_by(desc(Flow.created))
q = q.offset(start).limit(limit)
for flow in q.all():
flows.append(flow.get_json())
Expand Down
6 changes: 3 additions & 3 deletions server/kraken/server/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class Branch(db.Model, DatesMixin):
primaryjoin="and_(Branch.id==Flow.branch_id, Flow.kind==0)", viewonly=True)
dev_flows = relationship("Flow", order_by="desc(Flow.created)",
primaryjoin="and_(Branch.id==Flow.branch_id, Flow.kind==1)", viewonly=True)
stages = relationship("Stage", back_populates="branch", lazy="dynamic", order_by="Stage.name")
stages = relationship("Stage", back_populates="branch", order_by="Stage.name")
sequences = relationship("BranchSequence", back_populates="branch")

#base_branch = relationship('BaseBranch', uselist=False, primaryjoin="or_(Branch.id==BaseBranch.ci_branch_id, Branch.id==BaseBranch.dev_branch_id)")
Expand All @@ -108,7 +108,7 @@ def get_json(self, with_results=False, with_cfg=False):
data['ci_flows'] = [f.get_json() for f in self.ci_flows[:10]]
data['dev_flows'] = [f.get_json() for f in self.dev_flows[:10]]
if with_cfg:
data['stages'] = [s.get_json() for s in self.stages.filter_by(deleted=None)]
data['stages'] = [s.get_json() for s in self.stages if s.deleted is None]
return data


Expand Down Expand Up @@ -277,7 +277,7 @@ def get_json(self):
project_id=self.branch.project_id,
project_name=self.branch.project.name,
args=self.args,
stages=[s.get_json() for s in self.branch.stages.filter_by(deleted=None)],
stages=[s.get_json() for s in self.branch.stages if s.deleted is None],
runs=[r.get_json() for r in self.runs],
trigger=trigger,
artifacts=self.artifacts)
Expand Down

0 comments on commit 1e0b1bc

Please sign in to comment.