Improved update of base collection via web socket.
This commit is contained in:
parent
94b7d1dff5
commit
59f9ed9604
7 changed files with 178 additions and 61 deletions
|
@ -1,5 +1,5 @@
|
||||||
module ExtraCollection
|
module ExtraCollection
|
||||||
def add(collections)
|
def session(collections)
|
||||||
|
|
||||||
# all base stuff
|
# all base stuff
|
||||||
collections['Role'] = Role.all
|
collections['Role'] = Role.all
|
||||||
|
@ -7,5 +7,13 @@ module ExtraCollection
|
||||||
collections['Organization'] = Organization.all
|
collections['Organization'] = Organization.all
|
||||||
|
|
||||||
end
|
end
|
||||||
module_function :add
|
def push(collections)
|
||||||
|
|
||||||
|
# all base stuff
|
||||||
|
collections['Role'] = Role.all
|
||||||
|
collections['Group'] = Group.all
|
||||||
|
collections['Organization'] = Organization.all
|
||||||
|
|
||||||
|
end
|
||||||
|
module_function :session, :push
|
||||||
end
|
end
|
|
@ -1,5 +1,5 @@
|
||||||
module ExtraCollection
|
module ExtraCollection
|
||||||
def add(collections)
|
def session(collections)
|
||||||
|
|
||||||
collections['Network'] = Network.all
|
collections['Network'] = Network.all
|
||||||
collections['NetworkCategory'] = Network::Category.all
|
collections['NetworkCategory'] = Network::Category.all
|
||||||
|
@ -7,5 +7,13 @@ module ExtraCollection
|
||||||
collections['NetworkPrivacy'] = Network::Privacy.all
|
collections['NetworkPrivacy'] = Network::Privacy.all
|
||||||
|
|
||||||
end
|
end
|
||||||
module_function :add
|
def push(collections)
|
||||||
|
|
||||||
|
collections['Network'] = Network.all
|
||||||
|
collections['NetworkCategory'] = Network::Category.all
|
||||||
|
collections['NetworkCategoryType'] = Network::Category::Type.all
|
||||||
|
collections['NetworkPrivacy'] = Network::Privacy.all
|
||||||
|
|
||||||
|
end
|
||||||
|
module_function :session, :push
|
||||||
end
|
end
|
|
@ -1,5 +1,5 @@
|
||||||
module ExtraCollection
|
module ExtraCollection
|
||||||
def add(collections)
|
def session(collections)
|
||||||
|
|
||||||
# all ticket stuff
|
# all ticket stuff
|
||||||
collections['TicketStateType'] = Ticket::StateType.all
|
collections['TicketStateType'] = Ticket::StateType.all
|
||||||
|
@ -15,5 +15,22 @@ module ExtraCollection
|
||||||
collections['EmailAddress'] = EmailAddress.all
|
collections['EmailAddress'] = EmailAddress.all
|
||||||
|
|
||||||
end
|
end
|
||||||
module_function :add
|
def push(collections)
|
||||||
|
|
||||||
|
# all ticket stuff
|
||||||
|
collections['TicketStateType'] = Ticket::StateType.all
|
||||||
|
collections['TicketState'] = Ticket::State.all
|
||||||
|
collections['TicketPriority'] = Ticket::Priority.all
|
||||||
|
collections['TicketArticleType'] = Ticket::Article::Type.all
|
||||||
|
collections['TicketArticleSender'] = Ticket::Article::Sender.all
|
||||||
|
|
||||||
|
# all signatures
|
||||||
|
collections['Signature'] = Signature.all
|
||||||
|
|
||||||
|
# all email addresses
|
||||||
|
collections['EmailAddress'] = EmailAddress.all
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
module_function :session, :push
|
||||||
end
|
end
|
|
@ -21,7 +21,7 @@ class SessionsController < ApplicationController
|
||||||
user = User.find_fulldata(user.id)
|
user = User.find_fulldata(user.id)
|
||||||
|
|
||||||
# auto population of default collections
|
# auto population of default collections
|
||||||
default_collection = default_collections()
|
default_collection = SessionHelper::default_collections()
|
||||||
|
|
||||||
# set session user_id
|
# set session user_id
|
||||||
session[:user_id] = user['id']
|
session[:user_id] = user['id']
|
||||||
|
@ -82,7 +82,7 @@ class SessionsController < ApplicationController
|
||||||
user = User.user_data_full( user_id )
|
user = User.user_data_full( user_id )
|
||||||
|
|
||||||
# auto population of default collections
|
# auto population of default collections
|
||||||
default_collection = default_collections()
|
default_collection = SessionHelper::default_collections()
|
||||||
|
|
||||||
# return current session
|
# return current session
|
||||||
render :json => {
|
render :json => {
|
||||||
|
@ -112,7 +112,7 @@ class SessionsController < ApplicationController
|
||||||
logger.info("AUTH IS NULL, SERVICE NOT LINKED TO ACCOUNT")
|
logger.info("AUTH IS NULL, SERVICE NOT LINKED TO ACCOUNT")
|
||||||
|
|
||||||
# redirect to app
|
# redirect to app
|
||||||
redirect_to '/app#'
|
redirect_to '/app'
|
||||||
end
|
end
|
||||||
|
|
||||||
# Create a new user or add an auth to existing user, depending on
|
# Create a new user or add an auth to existing user, depending on
|
||||||
|
@ -129,23 +129,7 @@ class SessionsController < ApplicationController
|
||||||
session[:user_id] = authorization.user.id
|
session[:user_id] = authorization.user.id
|
||||||
|
|
||||||
# redirect to app
|
# redirect to app
|
||||||
redirect_to '/app#'
|
redirect_to '/app'
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
|
||||||
def default_collections
|
|
||||||
|
|
||||||
# auto population collections, store all here
|
|
||||||
default_collection = {}
|
|
||||||
|
|
||||||
# load collections to deliver from external files
|
|
||||||
dir = File.expand_path('../', __FILE__)
|
|
||||||
files = Dir.glob( "#{dir}/sessions/collection_*.rb" )
|
|
||||||
for file in files
|
|
||||||
load file
|
|
||||||
ExtraCollection.add(default_collection)
|
|
||||||
end
|
|
||||||
|
|
||||||
return default_collection
|
|
||||||
end
|
|
||||||
end
|
end
|
|
@ -1,6 +1,9 @@
|
||||||
# Load the rails application
|
# Load the rails application
|
||||||
require File.expand_path('../application', __FILE__)
|
require File.expand_path('../application', __FILE__)
|
||||||
|
|
||||||
|
# load session helper
|
||||||
|
require 'session_helper'
|
||||||
|
|
||||||
# load module used to get current user for active recorde observer
|
# load module used to get current user for active recorde observer
|
||||||
require 'user_info'
|
require 'user_info'
|
||||||
|
|
||||||
|
|
32
lib/session_helper.rb
Normal file
32
lib/session_helper.rb
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
module SessionHelper
|
||||||
|
def self.default_collections
|
||||||
|
|
||||||
|
# auto population collections, store all here
|
||||||
|
default_collection = {}
|
||||||
|
|
||||||
|
# load collections to deliver from external files
|
||||||
|
dir = File.expand_path('../../', __FILE__)
|
||||||
|
files = Dir.glob( "#{dir}/app/controllers/sessions/collection_*.rb" )
|
||||||
|
for file in files
|
||||||
|
load file
|
||||||
|
ExtraCollection.session(default_collection)
|
||||||
|
end
|
||||||
|
|
||||||
|
return default_collection
|
||||||
|
end
|
||||||
|
def self.push_collections
|
||||||
|
|
||||||
|
# auto population collections, store all here
|
||||||
|
push_collections = {}
|
||||||
|
|
||||||
|
# load collections to deliver from external files
|
||||||
|
dir = File.expand_path('../../', __FILE__)
|
||||||
|
files = Dir.glob( "#{dir}/app/controllers/sessions/collection_*.rb" )
|
||||||
|
for file in files
|
||||||
|
load file
|
||||||
|
ExtraCollection.push(push_collections)
|
||||||
|
end
|
||||||
|
|
||||||
|
return push_collections
|
||||||
|
end
|
||||||
|
end
|
|
@ -210,7 +210,7 @@ class UserState
|
||||||
@user_id = user_id
|
@user_id = user_id
|
||||||
@data = {}
|
@data = {}
|
||||||
@cache_key = 'user_' + user_id.to_s
|
@cache_key = 'user_' + user_id.to_s
|
||||||
self.log "---user started user state"
|
self.log 'notify', "---user started user state"
|
||||||
|
|
||||||
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 } )
|
||||||
|
|
||||||
|
@ -225,11 +225,11 @@ class UserState
|
||||||
|
|
||||||
# check if user is still with min one open connection
|
# check if user is still with min one open connection
|
||||||
if !CacheIn.get( 'last_run_' + user.id.to_s )
|
if !CacheIn.get( 'last_run_' + user.id.to_s )
|
||||||
self.log "---user - closeing thread - no open user connection"
|
self.log 'notify', "---user - closeing thread - no open user connection"
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
self.log "---user - fetch user data"
|
self.log 'notice', "---user - fetch user data"
|
||||||
# overview
|
# overview
|
||||||
cache_key = @cache_key + '_overview'
|
cache_key = @cache_key + '_overview'
|
||||||
if CacheIn.expired(cache_key)
|
if CacheIn.expired(cache_key)
|
||||||
|
@ -237,9 +237,9 @@ class UserState
|
||||||
:current_user => user,
|
:current_user => user,
|
||||||
)
|
)
|
||||||
overview_cache = CacheIn.get( cache_key, { :re_expire => true } )
|
overview_cache = CacheIn.get( cache_key, { :re_expire => true } )
|
||||||
self.log 'fetch overview - ' + cache_key
|
self.log 'notice', 'fetch overview - ' + cache_key
|
||||||
if overview != overview_cache
|
if overview != overview_cache
|
||||||
self.log 'fetch overview changed - ' + cache_key
|
self.log 'notify', 'fetch overview changed - ' + cache_key
|
||||||
# puts overview.inspect
|
# puts overview.inspect
|
||||||
# puts '------'
|
# puts '------'
|
||||||
# puts overview_cache.inspect
|
# puts overview_cache.inspect
|
||||||
|
@ -261,9 +261,9 @@ class UserState
|
||||||
:array => true,
|
:array => true,
|
||||||
)
|
)
|
||||||
overview_data_cache = CacheIn.get( cache_key, { :re_expire => true } )
|
overview_data_cache = CacheIn.get( cache_key, { :re_expire => true } )
|
||||||
self.log 'fetch overview_data - ' + cache_key
|
self.log 'notice', 'fetch overview_data - ' + cache_key
|
||||||
if overview_data != overview_data_cache
|
if overview_data != overview_data_cache
|
||||||
self.log 'fetch overview_data changed - ' + cache_key
|
self.log 'notify', 'fetch overview_data changed - ' + cache_key
|
||||||
CacheIn.set( cache_key, overview_data, { :expires_in => 5.seconds } )
|
CacheIn.set( cache_key, overview_data, { :expires_in => 5.seconds } )
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -276,9 +276,9 @@ class UserState
|
||||||
:current_user_id => user.id,
|
:current_user_id => user.id,
|
||||||
)
|
)
|
||||||
ticket_create_attributes_cache = CacheIn.get( cache_key, { :re_expire => true } )
|
ticket_create_attributes_cache = CacheIn.get( cache_key, { :re_expire => true } )
|
||||||
self.log 'fetch ticket_create_attributes - ' + cache_key
|
self.log 'notice', 'fetch ticket_create_attributes - ' + cache_key
|
||||||
if ticket_create_attributes != ticket_create_attributes_cache
|
if ticket_create_attributes != ticket_create_attributes_cache
|
||||||
self.log 'fetch ticket_create_attributes changed - ' + cache_key
|
self.log 'notify', 'fetch ticket_create_attributes changed - ' + cache_key
|
||||||
CacheIn.set( cache_key, ticket_create_attributes, { :expires_in => 2.minutes } )
|
CacheIn.set( cache_key, ticket_create_attributes, { :expires_in => 2.minutes } )
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -288,9 +288,9 @@ class UserState
|
||||||
if CacheIn.expired(cache_key)
|
if CacheIn.expired(cache_key)
|
||||||
recent_viewed = History.recent_viewed(user)
|
recent_viewed = History.recent_viewed(user)
|
||||||
recent_viewed_cache = CacheIn.get( cache_key, { :re_expire => true } )
|
recent_viewed_cache = CacheIn.get( cache_key, { :re_expire => true } )
|
||||||
self.log 'fetch recent_viewed - ' + cache_key
|
self.log 'notice', 'fetch recent_viewed - ' + cache_key
|
||||||
if recent_viewed != recent_viewed_cache
|
if recent_viewed != recent_viewed_cache
|
||||||
self.log 'fetch recent_viewed changed - ' + cache_key
|
self.log 'notify', 'fetch recent_viewed changed - ' + cache_key
|
||||||
|
|
||||||
recent_viewed_full = History.recent_viewed_fulldata(user)
|
recent_viewed_full = History.recent_viewed_fulldata(user)
|
||||||
CacheIn.set( cache_key, recent_viewed, { :expires_in => 5.seconds } )
|
CacheIn.set( cache_key, recent_viewed, { :expires_in => 5.seconds } )
|
||||||
|
@ -303,9 +303,9 @@ class UserState
|
||||||
if CacheIn.expired(cache_key)
|
if CacheIn.expired(cache_key)
|
||||||
activity_stream = History.activity_stream( user )
|
activity_stream = History.activity_stream( user )
|
||||||
activity_stream_cache = CacheIn.get( cache_key, { :re_expire => true } )
|
activity_stream_cache = CacheIn.get( cache_key, { :re_expire => true } )
|
||||||
self.log 'fetch activity_stream - ' + cache_key
|
self.log 'notice', 'fetch activity_stream - ' + cache_key
|
||||||
if activity_stream != activity_stream_cache
|
if activity_stream != activity_stream_cache
|
||||||
self.log 'fetch activity_stream changed - ' + cache_key
|
self.log 'notify', 'fetch activity_stream changed - ' + cache_key
|
||||||
|
|
||||||
activity_stream_full = History.activity_stream_fulldata( user )
|
activity_stream_full = History.activity_stream_fulldata( user )
|
||||||
CacheIn.set( cache_key, activity_stream, { :expires_in => 0.75.minutes } )
|
CacheIn.set( cache_key, activity_stream, { :expires_in => 0.75.minutes } )
|
||||||
|
@ -319,9 +319,9 @@ class UserState
|
||||||
url = 'http://www.heise.de/newsticker/heise-atom.xml'
|
url = 'http://www.heise.de/newsticker/heise-atom.xml'
|
||||||
rss_items = RSS.fetch( url, 8 )
|
rss_items = RSS.fetch( url, 8 )
|
||||||
rss_items_cache = CacheIn.get( cache_key, { :re_expire => true } )
|
rss_items_cache = CacheIn.get( cache_key, { :re_expire => true } )
|
||||||
self.log 'fetch rss - ' + cache_key
|
self.log 'notice', 'fetch rss - ' + cache_key
|
||||||
if rss_items != rss_items_cache
|
if rss_items != rss_items_cache
|
||||||
self.log 'fetch rss changed - ' + cache_key
|
self.log 'notify', 'fetch rss changed - ' + cache_key
|
||||||
CacheIn.set( cache_key, rss_items, { :expires_in => 2.minutes } )
|
CacheIn.set( cache_key, rss_items, { :expires_in => 2.minutes } )
|
||||||
CacheIn.set( cache_key + '_push', {
|
CacheIn.set( cache_key + '_push', {
|
||||||
head: 'Heise ATOM',
|
head: 'Heise ATOM',
|
||||||
|
@ -329,12 +329,46 @@ class UserState
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
self.log "---/user-"
|
|
||||||
|
# auto population of default collections
|
||||||
|
self.log 'notice', "---user - fetch push_collection data"
|
||||||
|
|
||||||
|
# get available collections
|
||||||
|
cache_key = @cache_key + '_push_collections'
|
||||||
|
collections = CacheIn.get( cache_key )
|
||||||
|
if !collections
|
||||||
|
collections = {}
|
||||||
|
push_collection = SessionHelper::push_collections()
|
||||||
|
push_collection.each { | key, value |
|
||||||
|
collections[ key ] = true
|
||||||
|
}
|
||||||
|
CacheIn.set( cache_key, collections )
|
||||||
|
end
|
||||||
|
|
||||||
|
# check all collections to push
|
||||||
|
push_collection = {}
|
||||||
|
collections.each { | key, v |
|
||||||
|
cache_key = @cache_key + '_push_collections_' + key
|
||||||
|
if CacheIn.expired(cache_key)
|
||||||
|
if push_collection.empty?
|
||||||
|
push_collection = SessionHelper::push_collections()
|
||||||
|
end
|
||||||
|
push_collection_cache = CacheIn.get( cache_key, { :re_expire => true } )
|
||||||
|
self.log 'notice', "---user - fetch push_collection data " + cache_key
|
||||||
|
if !push_collection[key] || !push_collection_cache || push_collection[key] != push_collection_cache || !push_collection[ key ].zip( push_collection_cache ).all? { |x, y| x.attributes == y.attributes }
|
||||||
|
self.log 'notify', 'fetch push_collection changed - ' + cache_key
|
||||||
|
CacheIn.set( cache_key, push_collection[key], { :expires_in => 1.minutes } )
|
||||||
|
end
|
||||||
|
end
|
||||||
|
}
|
||||||
|
|
||||||
|
self.log 'notice', "---/user-"
|
||||||
sleep 1
|
sleep 1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def log( data )
|
def log( level, data )
|
||||||
|
return if level == 'notice'
|
||||||
puts "#{Time.now}:user_id(#{ @user_id }) #{ data }"
|
puts "#{Time.now}:user_id(#{ @user_id }) #{ data }"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -343,11 +377,12 @@ end
|
||||||
class ClientState
|
class ClientState
|
||||||
def initialize( client_id )
|
def initialize( client_id )
|
||||||
@client_id = client_id
|
@client_id = client_id
|
||||||
|
@cache_key = ''
|
||||||
@data = {}
|
@data = {}
|
||||||
@pushed = {}
|
@pushed = {}
|
||||||
self.log "---client start ws connection---"
|
self.log 'notify', "---client start ws connection---"
|
||||||
self.fetch
|
self.fetch
|
||||||
self.log "---client exiting ws connection---"
|
self.log 'notify', "---client exiting ws connection---"
|
||||||
end
|
end
|
||||||
|
|
||||||
def fetch
|
def fetch
|
||||||
|
@ -362,20 +397,23 @@ class ClientState
|
||||||
user = User.find( user_session[:id] )
|
user = User.find( user_session[:id] )
|
||||||
return if !user
|
return if !user
|
||||||
|
|
||||||
|
# set cache key
|
||||||
|
@cache_key = 'user_' + user.id.to_s
|
||||||
|
|
||||||
loop_count += 1
|
loop_count += 1
|
||||||
self.log "---client - looking for data of user #{user.id}"
|
self.log 'notice', "---client - looking for data of user #{user.id}"
|
||||||
|
|
||||||
# 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 } )
|
||||||
|
|
||||||
# overview
|
# overview
|
||||||
cache_key = 'user_' + user.id.to_s + '_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 } )
|
||||||
if overview_time && @data[:overview_time] != overview_time
|
if overview_time && @data[:overview_time] != overview_time
|
||||||
@data[:overview_time] = overview_time
|
@data[:overview_time] = overview_time
|
||||||
overview = CacheIn.get( cache_key, { :ignore_expire => true } )
|
overview = CacheIn.get( cache_key, { :ignore_expire => true } )
|
||||||
|
|
||||||
self.log "push overview for user #{user.id}"
|
self.log 'notify', "push overview for user #{user.id}"
|
||||||
|
|
||||||
# send update to browser
|
# send update to browser
|
||||||
self.transaction({
|
self.transaction({
|
||||||
|
@ -389,13 +427,13 @@ class ClientState
|
||||||
:current_user => user,
|
:current_user => user,
|
||||||
)
|
)
|
||||||
overviews.each { |overview|
|
overviews.each { |overview|
|
||||||
cache_key = 'user_' + user.id.to_s + '_overview_data_' + overview.meta[:url]
|
cache_key = @cache_key + '_overview_data_' + overview.meta[:url]
|
||||||
|
|
||||||
overview_data_time = CacheIn.get_time( cache_key, { :ignore_expire => true } )
|
overview_data_time = CacheIn.get_time( cache_key, { :ignore_expire => true } )
|
||||||
if overview_data_time && @data[cache_key] != overview_data_time
|
if overview_data_time && @data[cache_key] != overview_data_time
|
||||||
@data[cache_key] = overview_data_time
|
@data[cache_key] = overview_data_time
|
||||||
overview_data = CacheIn.get( cache_key, { :ignore_expire => true } )
|
overview_data = CacheIn.get( cache_key, { :ignore_expire => true } )
|
||||||
self.log "push overview_data for user #{user.id}"
|
self.log 'notify', "push overview_data for user #{user.id}"
|
||||||
users = {}
|
users = {}
|
||||||
tickets = []
|
tickets = []
|
||||||
overview_data[:tickets].each {|ticket_id|
|
overview_data[:tickets].each {|ticket_id|
|
||||||
|
@ -446,7 +484,7 @@ class ClientState
|
||||||
}
|
}
|
||||||
|
|
||||||
# ticket_create_attributes
|
# ticket_create_attributes
|
||||||
cache_key = 'user_' + user.id.to_s + '_ticket_create_attributes'
|
cache_key = @cache_key + '_ticket_create_attributes'
|
||||||
ticket_create_attributes_time = CacheIn.get_time( cache_key, { :ignore_expire => true } )
|
ticket_create_attributes_time = CacheIn.get_time( cache_key, { :ignore_expire => true } )
|
||||||
if ticket_create_attributes_time && @data[:ticket_create_attributes_time] != ticket_create_attributes_time
|
if ticket_create_attributes_time && @data[:ticket_create_attributes_time] != ticket_create_attributes_time
|
||||||
@data[:ticket_create_attributes_time] = ticket_create_attributes_time
|
@data[:ticket_create_attributes_time] = ticket_create_attributes_time
|
||||||
|
@ -461,7 +499,7 @@ class ClientState
|
||||||
:users => users,
|
:users => users,
|
||||||
:edit_form => create_attributes,
|
:edit_form => create_attributes,
|
||||||
}
|
}
|
||||||
self.log "push ticket_create_attributes for user #{user.id}"
|
self.log 'notify', "push ticket_create_attributes for user #{user.id}"
|
||||||
|
|
||||||
# send update to browser
|
# send update to browser
|
||||||
self.transaction({
|
self.transaction({
|
||||||
|
@ -471,12 +509,12 @@ class ClientState
|
||||||
end
|
end
|
||||||
|
|
||||||
# recent viewed
|
# recent viewed
|
||||||
cache_key = 'user_' + user.id.to_s + '_recent_viewed'
|
cache_key = @cache_key + '_recent_viewed'
|
||||||
recent_viewed_time = CacheIn.get_time( cache_key, { :ignore_expire => true } )
|
recent_viewed_time = CacheIn.get_time( cache_key, { :ignore_expire => true } )
|
||||||
if recent_viewed_time && @data[:recent_viewed_time] != recent_viewed_time
|
if recent_viewed_time && @data[:recent_viewed_time] != recent_viewed_time
|
||||||
@data[:recent_viewed_time] = recent_viewed_time
|
@data[:recent_viewed_time] = recent_viewed_time
|
||||||
recent_viewed = CacheIn.get( cache_key, { :ignore_expire => true } )
|
recent_viewed = CacheIn.get( cache_key, { :ignore_expire => true } )
|
||||||
self.log "push recent_viewed for user #{user.id}"
|
self.log 'notify', "push recent_viewed for user #{user.id}"
|
||||||
|
|
||||||
# send update to browser
|
# send update to browser
|
||||||
r = CacheIn.get( cache_key + '_push', { :ignore_expire => true } )
|
r = CacheIn.get( cache_key + '_push', { :ignore_expire => true } )
|
||||||
|
@ -487,12 +525,12 @@ class ClientState
|
||||||
end
|
end
|
||||||
|
|
||||||
# activity stream
|
# activity stream
|
||||||
cache_key = 'user_' + user.id.to_s + '_activity_stream'
|
cache_key = @cache_key + '_activity_stream'
|
||||||
activity_stream_time = CacheIn.get_time( cache_key, { :ignore_expire => true } )
|
activity_stream_time = CacheIn.get_time( cache_key, { :ignore_expire => true } )
|
||||||
if activity_stream_time && @data[:activity_stream_time] != activity_stream_time
|
if activity_stream_time && @data[:activity_stream_time] != activity_stream_time
|
||||||
@data[:activity_stream_time] = activity_stream_time
|
@data[:activity_stream_time] = activity_stream_time
|
||||||
activity_stream = CacheIn.get( cache_key, { :ignore_expire => true } )
|
activity_stream = CacheIn.get( cache_key, { :ignore_expire => true } )
|
||||||
self.log "push activity_stream for user #{user.id}"
|
self.log 'notify', "push activity_stream for user #{user.id}"
|
||||||
|
|
||||||
# send update to browser
|
# send update to browser
|
||||||
r = CacheIn.get( cache_key + '_push', { :ignore_expire => true } )
|
r = CacheIn.get( cache_key + '_push', { :ignore_expire => true } )
|
||||||
|
@ -504,12 +542,12 @@ class ClientState
|
||||||
end
|
end
|
||||||
|
|
||||||
# rss
|
# rss
|
||||||
cache_key = 'user_' + user.id.to_s + '_rss'
|
cache_key = @cache_key + '_rss'
|
||||||
rss_items_time = CacheIn.get_time( cache_key, { :ignore_expire => true } )
|
rss_items_time = CacheIn.get_time( cache_key, { :ignore_expire => true } )
|
||||||
if rss_items_time && @data[:rss_time] != rss_items_time
|
if rss_items_time && @data[:rss_time] != rss_items_time
|
||||||
@data[:rss_time] = rss_items_time
|
@data[:rss_time] = rss_items_time
|
||||||
rss_items = CacheIn.get( cache_key, { :ignore_expire => true } )
|
rss_items = CacheIn.get( cache_key, { :ignore_expire => true } )
|
||||||
self.log "push rss for user #{user.id}"
|
self.log 'notify', "push rss for user #{user.id}"
|
||||||
|
|
||||||
# send update to browser
|
# send update to browser
|
||||||
r = CacheIn.get( cache_key + '_push', { :ignore_expire => true } )
|
r = CacheIn.get( cache_key + '_push', { :ignore_expire => true } )
|
||||||
|
@ -519,7 +557,33 @@ class ClientState
|
||||||
:data => r,
|
:data => r,
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
self.log "---/client-"
|
|
||||||
|
# push_collections
|
||||||
|
cache_key = @cache_key + '_push_collections'
|
||||||
|
collections = CacheIn.get( cache_key ) || {}
|
||||||
|
collections.each { | key, v |
|
||||||
|
collection_cache_key = @cache_key + '_push_collections_' + key
|
||||||
|
collection_time = CacheIn.get_time( collection_cache_key, { :ignore_expire => true } )
|
||||||
|
if collection_time && @data[ collection_cache_key + '_time' ] != collection_time
|
||||||
|
|
||||||
|
@data[ collection_cache_key + '_time' ] = collection_time
|
||||||
|
push_collections = CacheIn.get( collection_cache_key, { :ignore_expire => true } )
|
||||||
|
|
||||||
|
self.log 'notify', "push push_collections #{key} for user #{user.id}"
|
||||||
|
|
||||||
|
# send update to browser
|
||||||
|
data = {}
|
||||||
|
data['collections'] = {}
|
||||||
|
data['collections'][key] = push_collections
|
||||||
|
self.transaction({
|
||||||
|
:event => 'loadCollection',
|
||||||
|
:data => data,
|
||||||
|
})
|
||||||
|
|
||||||
|
end
|
||||||
|
}
|
||||||
|
|
||||||
|
self.log 'notice', "---/client-"
|
||||||
|
|
||||||
# start faster in the beginnig
|
# start faster in the beginnig
|
||||||
if loop_count < 20
|
if loop_count < 20
|
||||||
|
@ -561,7 +625,7 @@ class ClientState
|
||||||
@pushed[:users][user_id] = user
|
@pushed[:users][user_id] = user
|
||||||
|
|
||||||
# user not on client or different
|
# user not on client or different
|
||||||
self.log 'push user ... ' + user['login']
|
self.log 'notice', 'push user ... ' + user['login']
|
||||||
users[ user_id ] = user
|
users[ user_id ] = user
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -570,7 +634,8 @@ class ClientState
|
||||||
Session.transaction( @client_id, data )
|
Session.transaction( @client_id, data )
|
||||||
end
|
end
|
||||||
|
|
||||||
def log( data )
|
def log( level, data )
|
||||||
|
return if level == 'notice'
|
||||||
puts "#{Time.now}:client(#{ @client_id }) #{ data }"
|
puts "#{Time.now}:client(#{ @client_id }) #{ data }"
|
||||||
end
|
end
|
||||||
end
|
end
|
Loading…
Reference in a new issue