diff --git a/packages/database/src/core/Repo.ts b/packages/database/src/core/Repo.ts index 2e0338d8ad4..a935c197e60 100644 --- a/packages/database/src/core/Repo.ts +++ b/packages/database/src/core/Repo.ts @@ -55,7 +55,10 @@ import { } from './util/util'; import { AuthTokenProvider } from './AuthTokenProvider'; -import { StatsManager } from './stats/StatsManager'; +import { + statsManagerGetCollection, + statsManagerGetOrCreateReporter +} from './stats/StatsManager'; import { StatsReporter } from './stats/StatsReporter'; import { StatsListener } from './stats/StatsListener'; import { @@ -181,7 +184,7 @@ export class Repo { } export function repoStart(repo: Repo): void { - repo.stats_ = StatsManager.getCollection(repo.repoInfo_); + repo.stats_ = statsManagerGetCollection(repo.repoInfo_); if (repo.forceRestClient_ || beingCrawled()) { repo.server_ = new ReadonlyRestClient( @@ -245,7 +248,7 @@ export function repoStart(repo: Repo): void { // In the case of multiple Repos for the same repoInfo (i.e. there are multiple Firebase.Contexts being used), // we only want to create one StatsReporter. As such, we'll report stats over the first Repo created. - repo.statsReporter_ = StatsManager.getOrCreateReporter( + repo.statsReporter_ = statsManagerGetOrCreateReporter( repo.repoInfo_, () => new StatsReporter(repo.stats_, repo.server_) ); diff --git a/packages/database/src/core/stats/StatsManager.ts b/packages/database/src/core/stats/StatsManager.ts index d8a9e44bdfb..d3193c894b9 100644 --- a/packages/database/src/core/stats/StatsManager.ts +++ b/packages/database/src/core/stats/StatsManager.ts @@ -18,30 +18,28 @@ import { StatsCollection } from './StatsCollection'; import { RepoInfo } from '../RepoInfo'; -export class StatsManager { - private static collections_: { [k: string]: StatsCollection } = {}; - private static reporters_: { [k: string]: unknown } = {}; +const collections: { [k: string]: StatsCollection } = {}; +const reporters: { [k: string]: unknown } = {}; - static getCollection(repoInfo: RepoInfo): StatsCollection { - const hashString = repoInfo.toString(); +export function statsManagerGetCollection(repoInfo: RepoInfo): StatsCollection { + const hashString = repoInfo.toString(); - if (!this.collections_[hashString]) { - this.collections_[hashString] = new StatsCollection(); - } - - return this.collections_[hashString]; + if (!collections[hashString]) { + collections[hashString] = new StatsCollection(); } - static getOrCreateReporter( - repoInfo: RepoInfo, - creatorFunction: () => T - ): T { - const hashString = repoInfo.toString(); + return collections[hashString]; +} - if (!this.reporters_[hashString]) { - this.reporters_[hashString] = creatorFunction(); - } +export function statsManagerGetOrCreateReporter( + repoInfo: RepoInfo, + creatorFunction: () => T +): T { + const hashString = repoInfo.toString(); - return this.reporters_[hashString] as T; + if (!reporters[hashString]) { + reporters[hashString] = creatorFunction(); } + + return reporters[hashString] as T; } diff --git a/packages/database/src/realtime/BrowserPollConnection.ts b/packages/database/src/realtime/BrowserPollConnection.ts index 113cb2d6008..be541f18890 100644 --- a/packages/database/src/realtime/BrowserPollConnection.ts +++ b/packages/database/src/realtime/BrowserPollConnection.ts @@ -24,7 +24,7 @@ import { LUIDGenerator, splitStringBySize } from '../core/util/util'; -import { StatsManager } from '../core/stats/StatsManager'; +import { statsManagerGetCollection } from '../core/stats/StatsManager'; import { PacketReceiver } from './polling/PacketReceiver'; import { APPLICATION_ID_PARAM, @@ -37,7 +37,7 @@ import { TRANSPORT_SESSION_PARAM, VERSION_PARAM } from './Constants'; -import { base64Encode, stringify, isNodeSdk } from '@firebase/util'; +import { base64Encode, isNodeSdk, stringify } from '@firebase/util'; import { Transport } from './Transport'; import { RepoInfo, repoInfoConnectionURL } from '../core/RepoInfo'; @@ -114,7 +114,7 @@ export class BrowserPollConnection implements Transport { public lastSessionId?: string ) { this.log_ = logWrapper(connId); - this.stats_ = StatsManager.getCollection(repoInfo); + this.stats_ = statsManagerGetCollection(repoInfo); this.urlFn = (params: { [k: string]: string }) => repoInfoConnectionURL(repoInfo, LONG_POLLING, params); } diff --git a/packages/database/src/realtime/WebSocketConnection.ts b/packages/database/src/realtime/WebSocketConnection.ts index 2bcf6fd6b9e..167338b65bb 100644 --- a/packages/database/src/realtime/WebSocketConnection.ts +++ b/packages/database/src/realtime/WebSocketConnection.ts @@ -16,9 +16,9 @@ */ import { RepoInfo, repoInfoConnectionURL } from '../core/RepoInfo'; -import { assert, jsonEval, stringify, isNodeSdk } from '@firebase/util'; +import { assert, isNodeSdk, jsonEval, stringify } from '@firebase/util'; import { logWrapper, splitStringBySize } from '../core/util/util'; -import { StatsManager } from '../core/stats/StatsManager'; +import { statsManagerGetCollection } from '../core/stats/StatsManager'; import { FORGE_DOMAIN_RE, FORGE_REF, @@ -86,7 +86,7 @@ export class WebSocketConnection implements Transport { lastSessionId?: string ) { this.log_ = logWrapper(this.connId); - this.stats_ = StatsManager.getCollection(repoInfo); + this.stats_ = statsManagerGetCollection(repoInfo); this.connURL = WebSocketConnection.connectionURL_( repoInfo, transportSessionId,