trabajo-afectivo/lib/sessions/backend/base.rb

35 lines
1 KiB
Ruby
Raw Normal View History

2016-03-03 08:56:13 +00:00
class Sessions::Backend::Base
def initialize(user, asset_lookup, client, client_id, ttl = 10)
2016-03-03 08:56:13 +00:00
@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] ||= {}
@asset_lookup[class_name][record.id] = {
updated_at: record.updated_at,
pushed_at: Time.zone.now,
}
return true
end
if (!@asset_lookup[class_name][record.id][:updated_at] || @asset_lookup[class_name][record.id][:updated_at] < record.updated_at) ||
(!@asset_lookup[class_name][record.id][:pushed_at] || @asset_lookup[class_name][record.id][:pushed_at] > Time.zone.now - 45.seconds)
@asset_lookup[class_name][record.id] = {
updated_at: record.updated_at,
pushed_at: Time.zone.now,
}
2016-03-03 08:56:13 +00:00
return true
end
false
end
end