| @@ -162,8 +162,32 @@ | ||
| 162 | 162 | ); |
| 163 | 163 | } |
| 164 | 164 | |
| 165 | 165 | /** |
| 166 | + * The per-type write map for a normalized list, or nothing for an empty one. | |
| 167 | + * | |
| 168 | + * An empty list resolves no keys, so it needs no map. Asking the detector | |
| 169 | + * for one ran its recent-order scan on every POS order push (the app always | |
| 170 | + * sends `tax_ids`, usually empty), and that scan was the straw that | |
| 171 | + * exhausted a 128 MB request on a 5,500-order store. | |
| 172 | + * | |
| 173 | + * @param array<int,array<string,mixed>> $normalized Normalized TaxId[] input. | |
| 174 | + * @param null|array<string,string> $write_map Caller-supplied map, if any. | |
| 175 | + * | |
| 176 | + * @return array<string,string> | |
| 177 | + */ | |
| 178 | + private static function resolve_write_map( array $normalized, $write_map ): array { | |
| 179 | + if ( \is_array( $write_map ) ) { | |
| 180 | + return $write_map; | |
| 181 | + } | |
| 182 | + if ( array() === $normalized ) { | |
| 183 | + return array(); | |
| 184 | + } | |
| 185 | + | |
| 186 | + return ( new Tax_Id_Detector() )->summary()['write_map']; | |
| 187 | + } | |
| 188 | + | |
| 189 | + /** | |
| 166 | 190 | * Persist the given TaxId[] list onto a WooCommerce order. |
| 167 | 191 | * |
| 168 | 192 | * @param WC_Abstract_Order $order Order. |
| 169 | 193 | * @param array<int,mixed> $tax_ids Raw TaxId[] input. |
| @@ -172,9 +196,9 @@ | ||
| 172 | 196 | * @return array{updates:array<string,mixed>,owned:array<int,string>,verified:array<int,array<string,mixed>>} |
| 173 | 197 | */ |
| 174 | 198 | public function write_for_order( WC_Abstract_Order $order, array $tax_ids, $write_map = null ): array { |
| 175 | 199 | $normalized = self::normalize_input( $tax_ids ); |
| 176 | - $map = \is_array( $write_map ) ? $write_map : ( new Tax_Id_Detector() )->summary()['write_map']; | |
| 200 | + $map = self::resolve_write_map( $normalized, $write_map ); | |
| 177 | 201 | $canonical = self::canonicalize_for_storage( $normalized ); |
| 178 | 202 | |
| 179 | 203 | $plan = self::build_updates( $normalized, $map ); |
| 180 | 204 | |
| @@ -233,9 +257,9 @@ | ||
| 233 | 257 | ); |
| 234 | 258 | } |
| 235 | 259 | |
| 236 | 260 | $normalized = self::normalize_input( $tax_ids ); |
| 237 | - $map = \is_array( $write_map ) ? $write_map : ( new Tax_Id_Detector() )->summary()['write_map']; | |
| 261 | + $map = self::resolve_write_map( $normalized, $write_map ); | |
| 238 | 262 | $canonical = self::canonicalize_for_storage( $normalized ); |
| 239 | 263 | |
| 240 | 264 | $plan = self::build_updates( $normalized, $map ); |
| 241 | 265 | |