mirror of
https://github.com/gristlabs/grist-core.git
synced 2024-10-27 20:44:07 +00:00
51ff72c15e
Summary: Building: - Builds no longer wait for tsc for either client, server, or test targets. All use esbuild which is very fast. - Build still runs tsc, but only to report errors. This may be turned off with `SKIP_TSC=1` env var. - Grist-core continues to build using tsc. - Esbuild requires ES6 module semantics. Typescript's esModuleInterop is turned on, so that tsc accepts and enforces correct usage. - Client-side code is watched and bundled by webpack as before (using esbuild-loader) Code changes: - Imports must now follow ES6 semantics: `import * as X from ...` produces a module object; to import functions or class instances, use `import X from ...`. - Everything is now built with isolatedModules flag. Some exports were updated for it. Packages: - Upgraded browserify dependency, and related packages (used for the distribution-building step). - Building the distribution now uses esbuild's minification. babel-minify is no longer used. Test Plan: Should have no behavior changes, existing tests should pass, and docker image should build too. Reviewers: georgegevoian Reviewed By: georgegevoian Subscribers: alexmojaki Differential Revision: https://phab.getgrist.com/D3506
80 lines
2.6 KiB
TypeScript
80 lines
2.6 KiB
TypeScript
import {Document} from 'app/gen-server/entity/Document';
|
|
import {Organization} from 'app/gen-server/entity/Organization';
|
|
import {User} from 'app/gen-server/entity/User';
|
|
import {HomeDBManager} from 'app/gen-server/lib/HomeDBManager';
|
|
import log from 'app/server/lib/log';
|
|
|
|
// Frequency of logging usage information. Not something we need
|
|
// to track with much granularity.
|
|
const USAGE_PERIOD_MS = 1 * 60 * 60 * 1000; // log every 1 hour
|
|
|
|
/**
|
|
* Occasionally log usage information - number of users, orgs,
|
|
* docs, etc.
|
|
*/
|
|
export class Usage {
|
|
private _interval: NodeJS.Timeout;
|
|
private _currentOperation?: Promise<void>;
|
|
|
|
public constructor(private _dbManager: HomeDBManager) {
|
|
this._interval = setInterval(() => this.apply(), USAGE_PERIOD_MS);
|
|
// Log once at beginning, in case we roll over servers faster than
|
|
// the logging period for an extended length of time,
|
|
// and to raise the visibility of this logging step so if it gets
|
|
// slow devs notice.
|
|
this.apply();
|
|
}
|
|
|
|
/**
|
|
* Remove any scheduled operation, and wait for the current one to complete
|
|
* (if one is in progress).
|
|
*/
|
|
public async close() {
|
|
clearInterval(this._interval);
|
|
await this._currentOperation;
|
|
}
|
|
|
|
public apply() {
|
|
if (!this._currentOperation) {
|
|
this._currentOperation = this._apply()
|
|
.finally(() => this._currentOperation = undefined);
|
|
}
|
|
}
|
|
|
|
private async _apply(): Promise<void> {
|
|
try {
|
|
const manager = this._dbManager.connection.manager;
|
|
// raw count of users
|
|
const userCount = await manager.count(User);
|
|
// users who have logged in at least once
|
|
const userWithLoginCount = await manager.createQueryBuilder()
|
|
.from(User, 'users')
|
|
.where('first_login_at is not null')
|
|
.getCount();
|
|
// raw count of organizations (excluding personal orgs)
|
|
const orgCount = await manager.createQueryBuilder()
|
|
.from(Organization, 'orgs')
|
|
.where('owner_id is null')
|
|
.getCount();
|
|
// organizations with subscriptions that are in a non-terminated state
|
|
const orgInGoodStandingCount = await manager.createQueryBuilder()
|
|
.from(Organization, 'orgs')
|
|
.leftJoin('orgs.billingAccount', 'billing_accounts')
|
|
.where('owner_id is null')
|
|
.andWhere('billing_accounts.in_good_standing = true')
|
|
.getCount();
|
|
// raw count of documents
|
|
const docCount = await manager.count(Document);
|
|
log.rawInfo('activity', {
|
|
docCount,
|
|
orgCount,
|
|
orgInGoodStandingCount,
|
|
userCount,
|
|
userWithLoginCount,
|
|
});
|
|
} catch (e) {
|
|
log.warn("Error in Usage._apply", e);
|
|
}
|
|
}
|
|
}
|