Automattic / Automattic/VIP-Coding-Standards

New Sniff: wp_get_post_revisions memory issues

オープン
#468 コメント 2 件 リアクション 0 件 担当者 0 名 GitHub で見る
Standard: VIP-Go Type: Enhancement
主要言語
PHP
スター
261
フォーク
44
平均マージ
19分
マージ済み PR(30日)
1

説明

## What problem would the enhancement address for VIP?
`wp_get_post_revisions` can be problematic because it loads the entire post object for each revision. I've seen this in CLI commands and other places, where you might be looping through a set of posts, and then suddenly have to load the entire post objects for every revision a post has. If those revisions are large and numerous - it quickly fails.

Related trac: https://core.trac.wordpress.org/ticket/34560

## Describe the solution you'd like
We should suggest they only get the IDs for the revisions instead of the whole object:

```
wp_get_post_revisions( $post->ID, array( 'fields' => 'ids' ) );
```

## What code should be reported as a violation?

Anything that doesn't have the fields argument, like:

```
wp_get_post_revisions( $post->ID );
```

## What code should *not* be reported as a violation?

Getting the `ids` field or other fields instead of the whole object.
```
wp_get_post_revisions( $post->ID, array( 'fields' => 'ids' ) );
```

コントリビューションガイド

コントリビューションガイドを開く

調査の方向性

issue の違反する wp_get_post_revisions の例と許可されている例、およびリンクされている WordPress Trac チケットから始めます。fields 引数のない呼び出しが報告され、ids または別の fields 値を要求する呼び出しは報告されなければ完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
php
領域
performance, tooling
issue の種類
機能追加
難易度
3/5
見積もり時間
1〜2日
活発さ
停滞
明瞭さ
明確に書かれている
初心者へのやさしさ
38/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。