Skip to content

Commit 5e64b39

Browse files
b1ink0westonruter
andcommitted
Refactor to make source property readonly
Co-authored-by: Weston Ruter <[email protected]>
1 parent 2550f96 commit 5e64b39

File tree

4 files changed

+4
-8
lines changed

4 files changed

+4
-8
lines changed

plugins/optimization-detective/class-od-url-metric.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
* timestamp: float,
4545
* viewport: ViewportRect,
4646
* elements: ElementData[],
47-
* source?: non-empty-string,
47+
* source?: 'visitor'|'user'|'synthetic',
4848
* }
4949
* @phpstan-type JSONSchema array{
5050
* type: string|string[],
@@ -315,6 +315,7 @@ public static function get_json_schema(): array {
315315
'description' => __( 'The source of the URL Metric.', 'optimization-detective' ),
316316
'type' => 'string',
317317
'required' => false,
318+
'readonly' => true, // Omit from REST API.
318319
'enum' => array(
319320
'visitor',
320321
'user',
@@ -542,7 +543,7 @@ function ( array $element ): OD_Element {
542543
*
543544
* @since n.e.x.t
544545
*
545-
* @return non-empty-string|null Source.
546+
* @return 'visitor'|'user'|'synthetic'|null Source.
546547
*/
547548
public function get_source(): ?string {
548549
return $this->data['source'] ?? null;

plugins/optimization-detective/detect.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -919,13 +919,8 @@ export default async function detect( {
919919
height: win.innerHeight,
920920
},
921921
elements: [],
922-
source: restApiNonce ? 'user' : 'visitor',
923922
};
924923

925-
if ( odPrimeUrlMetricsVerificationToken ) {
926-
urlMetric.source = 'synthetic';
927-
}
928-
929924
const lcpMetric = lcpMetricCandidates.at( -1 );
930925

931926
// Populate the elements in the URL Metric.

plugins/optimization-detective/storage/class-od-rest-url-metrics-store-endpoint.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,7 @@ public function handle_rest_request( WP_REST_Request $request ) {
228228
'timestamp' => microtime( true ),
229229
'uuid' => wp_generate_uuid4(),
230230
'etag' => $request->get_param( 'current_etag' ),
231+
'source' => '' !== (string) $request->get_param( 'prime_url_metrics_verification_token' ) ? 'synthetic' : ( is_user_logged_in() ? 'user' : 'visitor' ),
231232
)
232233
)
233234
);

plugins/optimization-detective/types.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ export interface URLMetric {
2828
height: number;
2929
};
3030
elements: ElementData[];
31-
source: 'visitor' | 'user' | 'synthetic';
3231
}
3332

3433
export type ExtendedRootData = ExcludeProps< URLMetric >;

0 commit comments

Comments
 (0)