Commit a4dd08f
committed
REST API: Cache route maps in
`get_routes()` is called multiple times per request (route matching, schema generation, OPTIONS handling). The result is deterministic between route registrations, so this commit memoizes the per-namespace map on the server instance and busts the cache whenever `register_route()` mutates `$this->endpoints`.
Adds tests covering:
* `rest_endpoints` filter fires once across repeated calls.
* Cache keyed by namespace.
* Cache invalidation when a new route is registered.
* Cached and uncached results are identical.
Note for reviewers: caching the post-`rest_endpoints`-filter result means filters added after the first call to `get_routes()` no longer take effect for that request. This matches the perf goal but is a documented filter-contract change worth weighing.
See #39473.WP_REST_Server::get_routes().1 parent baa9f53 commit a4dd08f
2 files changed
Lines changed: 100 additions & 0 deletions
File tree
- src/wp-includes/rest-api
- tests/phpunit/tests/rest-api
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
87 | 87 | | |
88 | 88 | | |
89 | 89 | | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
90 | 98 | | |
91 | 99 | | |
92 | 100 | | |
| |||
924 | 932 | | |
925 | 933 | | |
926 | 934 | | |
| 935 | + | |
| 936 | + | |
| 937 | + | |
927 | 938 | | |
928 | 939 | | |
929 | 940 | | |
| |||
949 | 960 | | |
950 | 961 | | |
951 | 962 | | |
| 963 | + | |
| 964 | + | |
| 965 | + | |
| 966 | + | |
| 967 | + | |
| 968 | + | |
952 | 969 | | |
953 | 970 | | |
954 | 971 | | |
| |||
1016 | 1033 | | |
1017 | 1034 | | |
1018 | 1035 | | |
| 1036 | + | |
| 1037 | + | |
1019 | 1038 | | |
1020 | 1039 | | |
1021 | 1040 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2012 | 2012 | | |
2013 | 2013 | | |
2014 | 2014 | | |
| 2015 | + | |
| 2016 | + | |
| 2017 | + | |
| 2018 | + | |
| 2019 | + | |
| 2020 | + | |
| 2021 | + | |
| 2022 | + | |
| 2023 | + | |
| 2024 | + | |
| 2025 | + | |
| 2026 | + | |
| 2027 | + | |
| 2028 | + | |
| 2029 | + | |
| 2030 | + | |
| 2031 | + | |
| 2032 | + | |
| 2033 | + | |
| 2034 | + | |
| 2035 | + | |
| 2036 | + | |
| 2037 | + | |
| 2038 | + | |
| 2039 | + | |
| 2040 | + | |
| 2041 | + | |
| 2042 | + | |
| 2043 | + | |
| 2044 | + | |
| 2045 | + | |
| 2046 | + | |
| 2047 | + | |
| 2048 | + | |
| 2049 | + | |
| 2050 | + | |
| 2051 | + | |
| 2052 | + | |
| 2053 | + | |
| 2054 | + | |
| 2055 | + | |
| 2056 | + | |
| 2057 | + | |
| 2058 | + | |
| 2059 | + | |
| 2060 | + | |
| 2061 | + | |
| 2062 | + | |
| 2063 | + | |
| 2064 | + | |
| 2065 | + | |
| 2066 | + | |
| 2067 | + | |
| 2068 | + | |
| 2069 | + | |
| 2070 | + | |
| 2071 | + | |
| 2072 | + | |
| 2073 | + | |
| 2074 | + | |
| 2075 | + | |
| 2076 | + | |
| 2077 | + | |
| 2078 | + | |
| 2079 | + | |
| 2080 | + | |
| 2081 | + | |
| 2082 | + | |
| 2083 | + | |
| 2084 | + | |
| 2085 | + | |
| 2086 | + | |
| 2087 | + | |
| 2088 | + | |
| 2089 | + | |
| 2090 | + | |
| 2091 | + | |
| 2092 | + | |
| 2093 | + | |
| 2094 | + | |
| 2095 | + | |
2015 | 2096 | | |
2016 | 2097 | | |
2017 | 2098 | | |
| |||
0 commit comments