2016-03-03 08:56:13 +00:00
|
|
|
class Sessions::Backend::Base
|
2017-01-31 17:13:45 +00:00
|
|
|
|
2017-06-16 20:43:09 +00:00
|
|
|
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
|
2017-05-02 03:24:05 +00:00
|
|
|
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
|