Don't save data from pusher that won't likely be used

If user is logged in and doesn't keep 'recent repositories' tab opened, most of
the pusher events from 'common' channel are useless.

This commit introduces a logic to reject pusher events if:

  * recent tab hasn't been opened
  * user is signed in
  * Travis CI for open source is used
  * repository for a given event is not yet in store
  * repository for a given event is not part of current user's repositories
This commit is contained in:
Piotr Sarnacki 2015-02-04 19:31:46 +01:00
parent 426e67e7b4
commit 6f0eaf7091
3 changed files with 22 additions and 0 deletions

View File

@ -4,4 +4,7 @@
Route = MainTabRoute.extend
reposTabName: 'recent'
activate: ->
@store.set('recentReposOpened', true)
`export default Route`

View File

@ -1,4 +1,5 @@
`import DS from 'ember-data'`
`import config from 'travis/config/environment'`
Store = DS.Store.extend
defaultAdapter: 'application'
@ -7,6 +8,22 @@ Store = DS.Store.extend
receivePusherEvent: (event, data) ->
[name, type] = event.split(':')
auth = @container.lookup('auth:main')
if !@get('recentReposOpened') && event != 'job:log' && auth.get('signedIn') &&
!config.pro && !config.enterprise
# if recent repos hasn't been opened yet, we can safely
# drop any events that doesn't belong to repos owned by
# the logged in user and that aren't related to any
# repositories that are already opened
permissions = auth.get('permissions')
if name == 'job'
id = data.job.repository_id
else if name == 'build'
id = data.repository.id
return if !@hasRecordForId('repo', id) && !permissions.contains(id)
if name == 'job' && data.job?.commit
@pushPayload(commits: [data.job.commit])

View File

@ -144,4 +144,6 @@ Auth = Ember.Object.extend
"#{location.protocol}//www.gravatar.com/avatar/#{@get('currentUser.gravatarId')}?s=48&d=mm"
).property('currentUser.gravatarId')
permissions: Ember.computed.alias('currentUser.permissions')
`export default Auth`