improved push of data with has changed and was already pushed.
This commit is contained in:
parent
c6de8d1e30
commit
419ed6571c
3 changed files with 60 additions and 9 deletions
|
@ -140,10 +140,13 @@ class App.Controller extends Spine.Controller
|
||||||
return string
|
return string
|
||||||
|
|
||||||
userInfo: (data) =>
|
userInfo: (data) =>
|
||||||
|
el = data.el || $('#customer_info')
|
||||||
|
el.unbind()
|
||||||
|
|
||||||
# start customer info controller
|
# start customer info controller
|
||||||
new App.UserInfo(
|
new App.UserInfo(
|
||||||
el: data.el || $('#customer_info'),
|
el: el
|
||||||
user_id: data.user_id,
|
user_id: data.user_id
|
||||||
)
|
)
|
||||||
|
|
||||||
authenticate: ->
|
authenticate: ->
|
||||||
|
|
|
@ -157,10 +157,8 @@ class _Singleton extends Spine.Module
|
||||||
data = @_fillUp( type, data )
|
data = @_fillUp( type, data )
|
||||||
if callback
|
if callback
|
||||||
callback( data )
|
callback( data )
|
||||||
console.log 'find', type, data
|
|
||||||
return data
|
return data
|
||||||
else
|
else
|
||||||
console.log 'find not exists', type, data
|
|
||||||
if force
|
if force
|
||||||
@log 'Collection', 'debug', 'find forced to load!', type, id
|
@log 'Collection', 'debug', 'find forced to load!', type, id
|
||||||
else
|
else
|
||||||
|
@ -173,7 +171,11 @@ class _Singleton extends Spine.Module
|
||||||
data = App.Collection.find( type, id )
|
data = App.Collection.find( type, id )
|
||||||
|
|
||||||
# load update to local storage
|
# load update to local storage
|
||||||
col.load( localStorage: false, type: type, data: [ data ], refresh: true )
|
clone = {}
|
||||||
|
for key, value of data
|
||||||
|
if typeof value isnt 'function'
|
||||||
|
clone[key] = value
|
||||||
|
col.load( localStorage: false, type: type, data: [ clone ], refresh: true )
|
||||||
|
|
||||||
callback( data )
|
callback( data )
|
||||||
|
|
||||||
|
|
|
@ -446,6 +446,52 @@ class ClientState
|
||||||
# remember last run
|
# remember last run
|
||||||
CacheIn.set( 'last_run_' + user.id.to_s , true, { :expires_in => 20.seconds } )
|
CacheIn.set( 'last_run_' + user.id.to_s , true, { :expires_in => 20.seconds } )
|
||||||
|
|
||||||
|
# verify already pushed data
|
||||||
|
if @pushed[:users]
|
||||||
|
users = {}
|
||||||
|
@pushed[:users].each {|user_id, user_o|
|
||||||
|
self.user( user_id, users )
|
||||||
|
}
|
||||||
|
if !users.empty?
|
||||||
|
users.each {|user_id, user_data|
|
||||||
|
self.log 'notify', "push update of already pushed user id #{user_id}"
|
||||||
|
}
|
||||||
|
# send update to browser
|
||||||
|
self.send({
|
||||||
|
:data => {
|
||||||
|
:collections => {
|
||||||
|
:User => users,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
:event => [ 'loadCollection', 'ticket_overview_rebuild' ],
|
||||||
|
});
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# verify already pushed data
|
||||||
|
if @pushed[:tickets]
|
||||||
|
tickets = []
|
||||||
|
users = {}
|
||||||
|
@pushed[:tickets].each {|ticket_id, ticket_data|
|
||||||
|
self.ticket( ticket_id, tickets, users )
|
||||||
|
}
|
||||||
|
if !tickets.empty?
|
||||||
|
tickets.each {|ticket_id|
|
||||||
|
self.log 'notify', "push update of already pushed ticket id #{ticket_id}"
|
||||||
|
}
|
||||||
|
# send update to browser
|
||||||
|
self.send({
|
||||||
|
:data => {
|
||||||
|
:collections => {
|
||||||
|
:Ticket => tickets,
|
||||||
|
:User => users,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
:event => [ 'loadCollection', 'ticket_overview_rebuild' ],
|
||||||
|
});
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
# overview
|
# overview
|
||||||
cache_key = @cache_key + '_overview'
|
cache_key = @cache_key + '_overview'
|
||||||
overview_time = CacheIn.get_time( cache_key, { :ignore_expire => true } )
|
overview_time = CacheIn.get_time( cache_key, { :ignore_expire => true } )
|
||||||
|
@ -640,8 +686,8 @@ class ClientState
|
||||||
@pushed[:tickets] = {}
|
@pushed[:tickets] = {}
|
||||||
end
|
end
|
||||||
ticket = Ticket.full_data(ticket_id)
|
ticket = Ticket.full_data(ticket_id)
|
||||||
if @pushed[:tickets][ticket_id] != ticket
|
if @pushed[:tickets][ticket_id] != ticket['updated_at']
|
||||||
@pushed[:tickets][ticket_id] = ticket
|
@pushed[:tickets][ticket_id] = ticket['updated_at']
|
||||||
tickets.push ticket
|
tickets.push ticket
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -661,8 +707,8 @@ class ClientState
|
||||||
user = User.user_data_full( user_id )
|
user = User.user_data_full( user_id )
|
||||||
|
|
||||||
# user is already on client and not changed
|
# user is already on client and not changed
|
||||||
return if @pushed[:users][ user_id ] == user
|
return if @pushed[:users][ user_id ] == user['updated_at']
|
||||||
@pushed[:users][user_id] = user
|
@pushed[:users][user_id] = user['updated_at']
|
||||||
|
|
||||||
# user not on client or different
|
# user not on client or different
|
||||||
self.log 'notice', 'push user ... ' + user['login']
|
self.log 'notice', 'push user ... ' + user['login']
|
||||||
|
|
Loading…
Reference in a new issue