Skip to content

Commit 133c963

Browse files
committed
Add log counts to replace-related-records
1 parent 7b22706 commit 133c963

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

packages/graph/src/-private/operations/replace-related-records.ts

+15-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { deprecate } from '@ember/debug';
22

3+
import { LOG_METRIC_COUNTS } from '@warp-drive/build-config/debugging';
34
import { DEPRECATE_RELATIONSHIP_REMOTE_UPDATE_CLEARING_LOCAL_STATE } from '@warp-drive/build-config/deprecations';
45
import { DEBUG } from '@warp-drive/build-config/env';
56
import { assert } from '@warp-drive/build-config/macros';
@@ -12,6 +13,12 @@ import { assertPolymorphicType } from '../debug/assert-polymorphic-type';
1213
import type { CollectionEdge } from '../edges/collection';
1314
import type { Graph } from '../graph';
1415

16+
function count(label: string) {
17+
// @ts-expect-error
18+
// eslint-disable-next-line
19+
globalThis.__WarpDriveMetricCountData[label] = (globalThis.__WarpDriveMetricCountData[label] || 0) + 1;
20+
}
21+
1522
/*
1623
case many:1
1724
========
@@ -75,7 +82,6 @@ export default function replaceRelatedRecords(graph: Graph, op: ReplaceRelatedRe
7582
}
7683
}
7784

78-
// FIXME: Add metric count for number of calls to this
7985
function replaceRelatedRecordsLocal(graph: Graph, op: ReplaceRelatedRecordsOperation, isRemote: boolean) {
8086
const identifiers = op.value;
8187
const relationship = graph.get(op.record, op.field);
@@ -88,6 +94,10 @@ function replaceRelatedRecordsLocal(graph: Graph, op: ReplaceRelatedRecordsOpera
8894
const wasDirty = relationship.isDirty;
8995
let localBecameDirty = false;
9096

97+
if (LOG_METRIC_COUNTS) {
98+
count(`replaceRelatedRecordsLocal ${'type' in record ? record.type : '<document>'} ${op.field}`);
99+
}
100+
91101
const onAdd = (identifier: StableRecordIdentifier) => {
92102
// Since we are diffing against the remote state, we check
93103
// if our previous local state did not contain this identifier
@@ -161,11 +171,14 @@ function replaceRelatedRecordsLocal(graph: Graph, op: ReplaceRelatedRecordsOpera
161171
}
162172
}
163173

164-
// FIXME: Add metric count for number of calls to this
165174
function replaceRelatedRecordsRemote(graph: Graph, op: ReplaceRelatedRecordsOperation, isRemote: boolean) {
166175
const identifiers = op.value;
167176
const relationship = graph.get(op.record, op.field);
168177

178+
if (LOG_METRIC_COUNTS) {
179+
count(`replaceRelatedRecordsRemote ${'type' in op.record ? op.record.type : '<document>'} ${op.field}`);
180+
}
181+
169182
assert(
170183
`You can only '${op.op}' on a hasMany relationship. ${op.record.type}.${op.field} is a ${relationship.definition.kind}`,
171184
isHasMany(relationship)

0 commit comments

Comments
 (0)