Removed not longer needed worker backend. Just notify client on change.

This commit is contained in:
Martin Edenhofer 2014-08-26 01:29:28 +02:00
parent 665fac5dd7
commit 75d10cbbe6
4 changed files with 43 additions and 60 deletions

View file

@ -3,6 +3,10 @@
class RecentView < ApplicationModel
belongs_to :object_lookup, :class_name => 'ObjectLookup'
after_create :notify_clients
after_update :notify_clients
after_destroy :notify_clients
def self.log( object, o_id, user )
# lookups
@ -61,6 +65,18 @@ class RecentView < ApplicationModel
:assets => assets,
}
end
def notify_clients
data = RecentView.list_fulldata( User.find(self.created_by_id), 10 )
Sessions.send_to(
self.created_by_id,
{
:event => 'update_recent_viewed',
:data => data,
}
)
end
class Object < ApplicationModel
end
end

View file

@ -281,6 +281,33 @@ returns
=begin
send message to recipient client
Sessions.send_to(user_id, data)
returns
true|false
=end
def self.send_to( user_id, data )
# list all current clients
client_list = self.sessions
client_list.each {|client_id|
session = Sessions.get(client_id)
next if !session
next if !session[:user]
next if !session[:user][:id]
next if session[:user][:id].to_i != user_id.to_i
Sessions.send( client_id, data )
}
true
end
=begin
send message to all client
Sessions.broadcast(data)

View file

@ -1,59 +0,0 @@
class Sessions::Backend::RecentViewed
def initialize( user, client = nil, client_id = nil )
@user = user
@client = client
@client_id = client_id
@last_change = nil
end
def load
# get whole collection
recent_viewed = RecentView.list( @user, 10 )
# no data exists
return if !recent_viewed
return if recent_viewed.empty?
# no change exists
return if @last_change == recent_viewed
# remember last state
@last_change = recent_viewed
RecentView.list_fulldata( @user, 10 )
end
def client_key
"as::load::#{ self.class.to_s }::#{ @user.id }::#{ @client_id }"
end
def push
# check timeout
timeout = Sessions::CacheIn.get( self.client_key )
return if timeout
# set new timeout
Sessions::CacheIn.set( self.client_key, true, { :expires_in => 15.seconds } )
data = self.load
return if !data||data.empty?
if !@client
return {
:event => 'update_recent_viewed',
:data => data,
}
end
@client.log 'notify', "push recent_viewed for user #{ @user.id }"
@client.send({
:event => 'update_recent_viewed',
:data => data,
})
end
end

View file

@ -15,7 +15,6 @@ class Sessions::Client
'Sessions::Backend::Collections',
'Sessions::Backend::Rss',
'Sessions::Backend::ActivityStream',
'Sessions::Backend::RecentViewed',
'Sessions::Backend::TicketCreate',
]