From 36d099667e063e9f53e3e483ad2cc7a11bb6f18f Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Tue, 1 Dec 2015 13:32:59 +0100 Subject: [PATCH] Download last_build for a branch when we get the branch from pusher `lastBuild` is a synchronous relationship on a branch model, so we need to have a build record present when we put a default branch from a repository model into the store. We don't send lastBuild's payload in pusher, so we need to get it using an ajax call, if it's not already in the store. In the future we may decide to make the relationship async, but I don't want to change the code at the moment --- app/services/store.coffee | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/app/services/store.coffee b/app/services/store.coffee index 02c1f94e..499b0818 100644 --- a/app/services/store.coffee +++ b/app/services/store.coffee @@ -71,9 +71,21 @@ Store = DS.Store.extend if type == 'build' && (json.repository || json.repo) data = json.repository || json.repo - if data.default_branch - data.default_branch.default_branch = true + default_branch = data.default_branch + if default_branch + default_branch.default_branch = true - @push(this.normalize('repo', data)) + last_build_id = default_branch.last_build_id + # a build is a synchronous relationship on a branch model, so we need to + # have a build record present when we put default_branch from a repository + # model into the store. We don't send last_build's payload in pusher, so + # we need to get it here, if it's not already in the store. In the future + # we may decide to make this relationship async, but I don't want to + # change the code at the moment + if build = @peekRecord('build', last_build_id) + @push(this.normalize('repo', data)) + else + @findRecord('build', last_build_id).then => + @push(this.normalize('repo', data)) `export default Store`