Push objects just once to client.

This commit is contained in:
Martin Edenhofer 2016-03-03 09:56:13 +01:00
parent 8cce6a6e40
commit 9d4c865979
12 changed files with 266 additions and 247 deletions

View file

@ -1,10 +1,11 @@
class Sessions::Backend::ActivityStream
def initialize(user, client = nil, client_id = nil, ttl = 25)
def initialize(user, asset_lookup, client = nil, client_id = nil, ttl = 25)
@user = user
@client = client
@client_id = client_id
@ttl = ttl
@asset_lookup = asset_lookup
@last_change = nil
end

View file

@ -0,0 +1,23 @@
class Sessions::Backend::Base
def initialize(user, asset_lookup, client, client_id, ttl = 30)
@user = user
@client = client
@client_id = client_id
@ttl = ttl
@asset_lookup = asset_lookup
@last_change = nil
end
def asset_needed?(record)
class_name = record.class.to_s
if !@asset_lookup || !@asset_lookup[class_name] || !@asset_lookup[class_name][record.id] || @asset_lookup[class_name][record.id] < record.updated_at
if !@asset_lookup[class_name]
@asset_lookup[class_name] = {}
end
@asset_lookup[class_name][record.id] = record.updated_at
return true
end
false
end
end

View file

@ -1,10 +1,11 @@
class Sessions::Backend::Collections
class Sessions::Backend::Collections < Sessions::Backend::Base
def initialize(user, client, client_id, ttl = 10)
def initialize(user, asset_lookup, client, client_id, ttl = 10)
@user = user
@client = client
@client_id = client_id
@ttl = ttl
@asset_lookup = asset_lookup
@backends = backend
end
@ -35,7 +36,7 @@ class Sessions::Backend::Collections
next if file.classify == 'Sessions::Backend::Collections::Base'
#puts "LOAD #{file.classify}---"
#next if file == ''
backend = file.classify.constantize.new(@user, @client, @client_id, @ttl)
backend = file.classify.constantize.new(@user, @asset_lookup, @client, @client_id, @ttl)
if backend
backends.push backend
end

View file

@ -1,11 +1,12 @@
class Sessions::Backend::Collections::Base
class Sessions::Backend::Collections::Base < Sessions::Backend::Base
class << self; attr_accessor :model, :roles, :not_roles end
def initialize(user, client, client_id, ttl)
def initialize(user, asset_lookup, client, client_id, ttl)
@user = user
@client = client
@client_id = client_id
@ttl = ttl
@asset_lookup = asset_lookup
@last_change = nil
end
@ -67,6 +68,7 @@ class Sessions::Backend::Collections::Base
# collect assets
assets = {}
items.each {|item|
next if !asset_needed?(item)
assets = item.assets(assets)
}
if !@client

View file

@ -1,13 +1,6 @@
require 'rss'
class Sessions::Backend::Rss
def initialize(user, client, client_id, ttl = 30)
@user = user
@client = client
@ttl = ttl
@client_id = client_id
end
class Sessions::Backend::Rss < Sessions::Backend::Base
def collection_key
"rss::load::#{self.class}::#{@user.id}"

View file

@ -1,11 +1,4 @@
class Sessions::Backend::TicketCreate
def initialize(user, client = nil, client_id = nil, ttl = 30)
@user = user
@client = client
@client_id = client_id
@ttl = ttl
@last_change = nil
end
class Sessions::Backend::TicketCreate < Sessions::Backend::Base
def load

View file

@ -1,15 +1,16 @@
class Sessions::Backend::TicketOverviewList
class Sessions::Backend::TicketOverviewList < Sessions::Backend::Base
def self.reset(user_id)
key = "TicketOverviewPull::#{user_id}"
Cache.write(key, { needed: true })
end
def initialize(user, client = nil, client_id = nil, ttl = 8)
def initialize(user, asset_lookup, client = nil, client_id = nil, ttl = 8)
@user = user
@client = client
@client_id = client_id
@ttl = ttl
@asset_lookup = asset_lookup
@last_change = nil
@last_overview = {}
@last_overview_change = nil
@ -96,9 +97,12 @@ class Sessions::Backend::TicketOverviewList
assets = {}
overview = Overview.lookup(id: index[:overview][:id])
if asset_needed?(overview)
assets = overview.assets(assets)
end
index[:tickets].each {|ticket_meta|
ticket = Ticket.lookup(id: ticket_meta[:id])
next if !asset_needed?(ticket)
assets = ticket.assets(assets)
}

View file

@ -17,6 +17,7 @@ class Sessions::Client
'Sessions::Backend::TicketCreate',
]
asset_lookup = {}
backend_pool = []
user_id_last_run = nil
loop_count = 0
@ -33,6 +34,7 @@ class Sessions::Client
# init new backends
if user_id_last_run != user.id
user_id_last_run = user.id
asset_lookup = {}
# release old objects
backend_pool.collect! {
@ -42,7 +44,7 @@ class Sessions::Client
# create new pool
backend_pool = []
backends.each {|backend|
item = backend.constantize.new(user, self, @client_id)
item = backend.constantize.new(user, asset_lookup, self, @client_id)
backend_pool.push item
}
end

View file

@ -103,8 +103,8 @@ class SessionBasicTest < ActiveSupport::TestCase
UserInfo.current_user_id = 2
user = User.lookup(id: 1)
collection_client1 = Sessions::Backend::Collections::Group.new(user, false, '123-1', 3)
collection_client2 = Sessions::Backend::Collections::Group.new(user, false, '234-2', 3)
collection_client1 = Sessions::Backend::Collections::Group.new(user, {}, false, '123-1', 3)
collection_client2 = Sessions::Backend::Collections::Group.new(user, {}, false, '234-2', 3)
# get whole collections
result1 = collection_client1.push
@ -190,8 +190,8 @@ class SessionBasicTest < ActiveSupport::TestCase
user = User.lookup(id: 1)
org = Organization.create( name: 'SomeOrg1::' + rand(999_999).to_s, active: true )
collection_client1 = Sessions::Backend::Collections::Organization.new(user, false, '123-1', 3)
collection_client2 = Sessions::Backend::Collections::Organization.new(user, false, '234-2', 3)
collection_client1 = Sessions::Backend::Collections::Organization.new(user, {}, false, '123-1', 3)
collection_client2 = Sessions::Backend::Collections::Organization.new(user, {}, false, '234-2', 3)
# get whole collections - should be nil, no org exists!
result1 = collection_client1.push
@ -240,7 +240,7 @@ class SessionBasicTest < ActiveSupport::TestCase
test 'c rss' do
user = User.lookup(id: 1)
collection_client1 = Sessions::Backend::Rss.new(user, false, '123-1')
collection_client1 = Sessions::Backend::Rss.new(user, {}, false, '123-1')
# get whole collections
result1 = collection_client1.push
@ -274,7 +274,7 @@ class SessionBasicTest < ActiveSupport::TestCase
agent1.roles = roles
assert(agent1.save, 'create/update agent1')
as_client1 = Sessions::Backend::ActivityStream.new(agent1, false, '123-1', 3)
as_client1 = Sessions::Backend::ActivityStream.new(agent1, {}, false, '123-1', 3)
# get as stream
result1 = as_client1.push
@ -304,7 +304,7 @@ class SessionBasicTest < ActiveSupport::TestCase
UserInfo.current_user_id = 2
user = User.lookup(id: 1)
ticket_create_client1 = Sessions::Backend::TicketCreate.new(user, false, '123-1', 3)
ticket_create_client1 = Sessions::Backend::TicketCreate.new(user, {}, false, '123-1', 3)
# get as stream
result1 = ticket_create_client1.push

View file

@ -28,7 +28,7 @@ class SessionBasicTicketTest < ActiveSupport::TestCase
Ticket.create(title: 'default overview test', group_id: 1, priority_id: 1, state_id: 1, customer_id: 1)
user = User.lookup(id: agent1.id)
client1 = Sessions::Backend::TicketOverviewList.new(user, false, '123-1', 5)
client1 = Sessions::Backend::TicketOverviewList.new(user, {}, false, '123-1', 5)
result1 = client1.push
assert(result1, 'check ticket_overview_List')

View file

@ -54,9 +54,9 @@ class SessionCollectionsTest < ActiveSupport::TestCase
customer1.roles = roles
customer1.save
collection_client1 = Sessions::Backend::Collections.new(agent1, nil, 'aaa-1', 3)
collection_client2 = Sessions::Backend::Collections.new(agent2, nil, 'bbb-2', 3)
collection_client3 = Sessions::Backend::Collections.new(customer1, nil, 'ccc-2', 3)
collection_client1 = Sessions::Backend::Collections.new(agent1, {}, nil, 'aaa-1', 3)
collection_client2 = Sessions::Backend::Collections.new(agent2, {}, nil, 'bbb-2', 3)
collection_client3 = Sessions::Backend::Collections.new(customer1, {}, nil, 'ccc-2', 3)
# get whole collections
result1 = collection_client1.push