Skip to content

Commit 8986003

Browse files
committed
Make 'etag' a required property of the URL Metric
Signed-off-by: Shyamsundar Gadde <[email protected]>
1 parent 2b1bf18 commit 8986003

File tree

3 files changed

+7
-18
lines changed

3 files changed

+7
-18
lines changed

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -286,11 +286,6 @@ public function is_complete(): bool {
286286
return false;
287287
}
288288

289-
// The ETag is not populated yet, so this is stale. Eventually this will be required.
290-
if ( $url_metric->get_etag() === null ) {
291-
return false;
292-
}
293-
294289
// The ETag of the URL Metric does not match the current ETag for the collection, so it is stale.
295290
if ( ! hash_equals( $url_metric->get_etag(), $this->collection->get_current_etag() ) ) {
296291
return false;

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
* }
4040
* @phpstan-type Data array{
4141
* uuid: non-empty-string,
42-
* etag?: non-empty-string,
42+
* etag: non-empty-string,
4343
* url: non-empty-string,
4444
* timestamp: float,
4545
* viewport: ViewportRect,
@@ -171,6 +171,7 @@ public function set_group( OD_URL_Metric_Group $group ): void {
171171
*
172172
* @since 0.1.0
173173
* @since 0.9.0 Added the 'etag' property to the schema.
174+
* @since n.e.x.t The 'etag' property is now required.
174175
*
175176
* @todo Cache the return value?
176177
*
@@ -230,7 +231,7 @@ public static function get_json_schema(): array {
230231
'pattern' => '^[0-9a-f]{32}\z',
231232
'minLength' => 32,
232233
'maxLength' => 32,
233-
'required' => false, // To be made required in a future release.
234+
'required' => true,
234235
'readonly' => true, // Omit from REST API.
235236
),
236237
'url' => array(
@@ -446,12 +447,12 @@ public function get_uuid(): string {
446447
* Gets ETag.
447448
*
448449
* @since 0.9.0
450+
* @since n.e.x.t No longer returns null as 'etag' is now required.
449451
*
450-
* @return non-empty-string|null ETag.
452+
* @return non-empty-string ETag.
451453
*/
452-
public function get_etag(): ?string {
453-
// Since the ETag is optional for now, return null for old URL Metrics that do not have one.
454-
return $this->data['etag'] ?? null;
454+
public function get_etag(): string {
455+
return $this->data['etag'];
455456
}
456457

457458
/**

plugins/optimization-detective/storage/class-od-url-metrics-post-type.php

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -226,13 +226,6 @@ public static function store_url_metric( string $slug, OD_URL_Metric $new_url_me
226226
}
227227

228228
$etag = $new_url_metric->get_etag();
229-
if ( null === $etag ) {
230-
// This case actually will never occur in practice because the store_url_metric function is only called
231-
// in the REST API endpoint where the ETag parameter is required. It is here exclusively for the sake of
232-
// PHPStan's static analysis. This entire condition can be removed in a future release when the 'etag'
233-
// property becomes required.
234-
return new WP_Error( 'missing_etag' );
235-
}
236229

237230
$group_collection = new OD_URL_Metric_Group_Collection(
238231
$url_metrics,

0 commit comments

Comments
 (0)