smc-hub
Version:
CoCalc: Backend webserver component
82 lines (71 loc) • 2.92 kB
text/coffeescript
#########################################################################
# This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.
# License: AGPLv3 s.t. "Commons Clause" – see LICENSE.md for details
#########################################################################
###
Class to track (and report in a log) stats about user_queries by the Rethink interface.
###
{defaults} = misc = require('smc-util/misc')
required = defaults.required
class exports.UserQueryStats
constructor: () ->
= {}
= {}
= {}
_cnt: (account_id, project_id, table, op, eps=1) =>
if account_id?
t = [account_id] ?= {}
else if project_id?
t = [project_id] ?= {}
else
return
s = t[table] ?= {}
s[op] ?= 0
s[op] += eps
report: (opts) =>
if opts.account_id?
t = [opts.account_id]
head = "account_id='#{opts.account_id}'"
else if opts.project_id?
t = [opts.project_id]
head = "project_id='#{opts.project_id}'"
else
return
set_query: (opts) =>
opts = defaults opts,
account_id : undefined
project_id : undefined
table : required
#
get_query: (opts) =>
opts = defaults opts,
account_id : undefined
project_id : undefined
table : required
#
changefeed: (opts) =>
opts = defaults opts,
account_id : undefined
project_id : undefined
table : required
changefeed_id : required
#
[opts.changefeed_id] = opts
cancel_changefeed: (opts) =>
opts = defaults opts,
changefeed_id : required
x = [opts.changefeed_id]
if not x?
return
{account_id, project_id, table} = [opts.changefeed_id]