From ab16a6fb34c0f3e4d9afed3332c559868201e606 Mon Sep 17 00:00:00 2001 From: Yorick Peterse Date: Fri, 10 Nov 2017 20:57:11 +0100 Subject: Optimise getting the pipeline status of commits This adds an optimised way of getting the latest pipeline status for a list of Commit objects (or just a single one). --- app/models/commit.rb | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'app/models/commit.rb') diff --git a/app/models/commit.rb b/app/models/commit.rb index 6dba154a6ea..a31ebe9cc87 100644 --- a/app/models/commit.rb +++ b/app/models/commit.rb @@ -80,6 +80,7 @@ class Commit @raw = raw_commit @project = project + @statuses = {} end def id @@ -236,11 +237,13 @@ class Commit end def status(ref = nil) - @statuses ||= {} - return @statuses[ref] if @statuses.key?(ref) - @statuses[ref] = pipelines.latest_status(ref) + @statuses[ref] = project.pipelines.latest_status_per_commit(id, ref)[id] + end + + def set_status_for_ref(ref, status) + @statuses[ref] = status end def signature -- cgit v1.2.1