mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-06-06 23:59:01 +02:00
Space editing sessions heartbeats with an increasing backoff
We send the first heartbeat as soon as the session start. The next ones are sent (if there's any activity) when the editing session is about 30 and 60 seconds. Then at 2min, 3min, 4min, 5min and later on every 5min. The backoff is not reset, so if due to inactivity the session expires in the server the backoff will still be the same.
This commit is contained in:
@@ -1,10 +1,15 @@
|
||||
define [
|
||||
"moment"
|
||||
"base"
|
||||
"modules/localStorage"
|
||||
], (App) ->
|
||||
|
||||
], (moment, App) ->
|
||||
CACHE_KEY = "mbEvents"
|
||||
EDIT_SESSION_HEARTBEAT_INTERVAL = 5 * 60 * 1000 # 5min
|
||||
|
||||
sessionStart = new Date()
|
||||
nextHeartbeat = new Date()
|
||||
|
||||
send = (category, action, attributes = {})->
|
||||
ga('send', 'event', category, action)
|
||||
event_name = "#{action}-#{category}"
|
||||
@@ -35,7 +40,22 @@ define [
|
||||
send: (category, action, label, value)->
|
||||
ga('send', 'event', category, action, label, value)
|
||||
|
||||
editingSessionHeartbeat: _.throttle( (segmentation = {}) ->
|
||||
|
||||
editingSessionHeartbeat: (segmentation = {}) ->
|
||||
return unless nextHeartbeat <= new Date()
|
||||
|
||||
@_sendEditingSessionHeartbeat(segmentation)
|
||||
|
||||
sessionDuration = (new Date().getTime() - sessionStart.getTime())/1000
|
||||
|
||||
backoffSecs = switch
|
||||
when sessionDuration < 60 then 30
|
||||
when sessionDuration < 300 then 60
|
||||
else 300
|
||||
|
||||
nextHeartbeat = moment().add(backoffSecs, 'seconds').toDate()
|
||||
|
||||
_sendEditingSessionHeartbeat: (segmentation) ->
|
||||
$http({
|
||||
url: "/editingSession/#{window.project_id}",
|
||||
method: "PUT",
|
||||
@@ -44,8 +64,6 @@ define [
|
||||
"X-CSRF-Token": window.csrfToken
|
||||
}
|
||||
})
|
||||
, EDIT_SESSION_HEARTBEAT_INTERVAL, trailing: false)
|
||||
|
||||
|
||||
sendMB: (key, segmentation = {}) ->
|
||||
$http {
|
||||
|
||||
Reference in New Issue
Block a user