Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/src/packages/hub/user-query-stats.coffee
Views: 687
#########################################################################1# This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.2# License: MS-RSL – see LICENSE.md for details3#########################################################################45###6Class to track (and report in a log) stats about user_queries by the Rethink interface.7###89{defaults} = misc = require('@cocalc/util/misc')10required = defaults.required1112class exports.UserQueryStats13constructor: (@dbg) ->14@_accounts = {}15@_projects = {}16@_feeds = {}1718_cnt: (account_id, project_id, table, op, eps=1) =>19if account_id?20t = @_accounts[account_id] ?= {}21else if project_id?22t = @_projects[project_id] ?= {}23else24return25s = t[table] ?= {}26s[op] ?= 027s[op] += eps2829report: (opts) =>30if opts.account_id?31t = @_accounts[opts.account_id]32head = "account_id='#{opts.account_id}'"33else if opts.project_id?34t = @_projects[opts.project_id]35head = "project_id='#{opts.project_id}'"36else37return38@dbg("#{head}: #{misc.to_json(t)}")3940set_query: (opts) =>41opts = defaults opts,42account_id : undefined43project_id : undefined44table : required45#@dbg("set_query(account_id='#{opts.account_id}',project_id='#{opts.project_id}',table='#{opts.table}')")46@_cnt(opts.account_id, opts.project_id, opts.table, 'set')47@report(opts)4849get_query: (opts) =>50opts = defaults opts,51account_id : undefined52project_id : undefined53table : required54#@dbg("get_query(account_id='#{opts.account_id}',project_id='#{opts.project_id}',table='#{opts.table}')")55@_cnt(opts.account_id, opts.project_id, opts.table, 'get')56@report(opts)5758changefeed: (opts) =>59opts = defaults opts,60account_id : undefined61project_id : undefined62table : required63changefeed_id : required64#@dbg("changefeed(account_id='#{opts.account_id}',project_id='#{opts.project_id}',table='#{opts.table}')")65@_cnt(opts.account_id, opts.project_id, opts.table, 'feed')66@_feeds[opts.changefeed_id] = opts67@report(opts)6869cancel_changefeed: (opts) =>70opts = defaults opts,71changefeed_id : required72@dbg("cancel_changefeed(changefeed_id='#{opts.changefeed_id}')")73x = @_feeds[opts.changefeed_id]74if not x?75@dbg("no such changefeed_id='#{opts.changefeed_id}'")76return77{account_id, project_id, table} = @_feeds[opts.changefeed_id]78@_cnt(account_id, project_id, table, 'feed', -1)79@report({account_id:account_id, project_id:project_id})80818283