Fix odd behavior on running jobs list and on queued jobs list

In order to not load too many repositories when not needed I was using
construct of repoData on Job and Worker models. repoData was a simple
object with id and slug attributes, which was used to generate url for a
repo. That way I didn't have to instantiate Repo object for generating
urls. The problem is that our API does not return repositorySlug along
with Job record, so the value of repositorySlug was overwritten and in
consequence repoData was becoming empty.

I could change the API, but I feel that the whole repoData concept is
flawed. A bit better solution is to load incomplete repository data into
the store (just an id and a slug) and then instantiate repo record - as
long as it will not need to provide other fields than an id and a slug,
we will not have to do an ajax request.
This commit is contained in:
Piotr Sarnacki 2013-05-15 16:54:59 +02:00
parent 895b52d7c4
commit 985e218981
6 changed files with 23 additions and 15 deletions

View File

@ -25,6 +25,14 @@ require 'travis/model'
_config: DS.attr('object')
repoSlugDidChange: (->
if slug = @get('repoSlug')
@get('store').loadIncomplete(Travis.Repo, {
id: @get('repoId'),
slug: slug
}, { skipIfExists: true })
).observes('repoSlug')
log: ( ->
@set('isLogAccessed', true)
Travis.Log.create(job: this)
@ -34,10 +42,6 @@ require 'travis/model'
@get('repositorySlug')
).property('repositorySlug')
repoData: (->
{ id: @get('repoId'), slug: @get('repoSlug') }
).property('repoSlug', 'repoId')
config: (->
Travis.Helpers.compact(@get('_config'))
).property('_config')

View File

@ -117,7 +117,7 @@ require 'travis/model'
@find(search: query, orderBy: 'name')
withLastBuild: ->
@filter( (repo) -> repo.get('lastBuildId') )
@filter( (repo) -> !repo.get('incomplete') && repo.get('lastBuildId') )
bySlug: (slug) ->
repo = $.select(@find().toArray(), (repo) -> repo.get('slug') == slug)

View File

@ -26,11 +26,15 @@ require 'travis/model'
@get('payload.job.number')
).property('jobNumber')
repoData: (->
{ id: @get('repoId'), slug: @get('repoSlug') }
).property('repoSlug', 'repoId')
repo: (->
id = @get('payload.repository.id') || @get('payload.repo.id')
slug = @get('repoSlug')
@get('store').loadIncomplete(Travis.Repo, {
id: id,
slug: slug
}, { skipIfExists: true })
Travis.Repo.find(@get('payload.repository.id') || @get('payload.repo.id'))
).property('payload.repository.id', 'payload.repo.id')

View File

@ -5,8 +5,8 @@
<ul class="jobs">
{{#each job in sortedJobs}}
<li class="job">
{{#if job.repoData.slug}}
{{#linkTo "job" job.repoData job}}
{{#if job.repo.slug}}
{{#linkTo "job" job.repo job}}
#{{job.number}}
{{/linkTo}}
{{/if}}

View File

@ -5,10 +5,10 @@
<ul {{bindAttr id="queue.id"}}>
{{#each job in queue}}
{{#view Travis.QueueItemView jobBinding="job"}}
{{#if job.repoSlug}}
{{#linkTo "job" job.repoData job}}
{{#if job.repo.slug}}
{{#linkTo "job" job.repo job}}
<span class="slug">
{{job.repoSlug}}
{{job.repo.slug}}
</span>
#{{job.number}}
{{/linkTo}}

View File

@ -14,7 +14,7 @@
<div class="status"></div>
{{#if worker.isWorking}}
{{#if worker.jobId}}
{{#linkTo "job" worker.repoData worker.jobId}}
{{#linkTo "job" worker.repo worker.jobId}}
{{view.display}}
{{/linkTo}}
{{/if}}