| @@ -162,32 +162,8 @@ | ||
| 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 | - /** | |
| 190 | 166 | * Persist the given TaxId[] list onto a WooCommerce order. |
| 191 | 167 | * |
| 192 | 168 | * @param WC_Abstract_Order $order Order. |
| 193 | 169 | * @param array<int,mixed> $tax_ids Raw TaxId[] input. |
| @@ -196,9 +172,9 @@ | ||
| 196 | 172 | * @return array{updates:array<string,mixed>,owned:array<int,string>,verified:array<int,array<string,mixed>>} |
| 197 | 173 | */ |
| 198 | 174 | public function write_for_order( WC_Abstract_Order $order, array $tax_ids, $write_map = null ): array { |
| 199 | 175 | $normalized = self::normalize_input( $tax_ids ); |
| 200 | - $map = self::resolve_write_map( $normalized, $write_map ); | |
| 176 | + $map = \is_array( $write_map ) ? $write_map : ( new Tax_Id_Detector() )->summary()['write_map']; | |
| 201 | 177 | $canonical = self::canonicalize_for_storage( $normalized ); |
| 202 | 178 | |
| 203 | 179 | $plan = self::build_updates( $normalized, $map ); |
| 204 | 180 | |
| @@ -257,9 +233,9 @@ | ||
| 257 | 233 | ); |
| 258 | 234 | } |
| 259 | 235 | |
| 260 | 236 | $normalized = self::normalize_input( $tax_ids ); |
| 261 | - $map = self::resolve_write_map( $normalized, $write_map ); | |
| 237 | + $map = \is_array( $write_map ) ? $write_map : ( new Tax_Id_Detector() )->summary()['write_map']; | |
| 262 | 238 | $canonical = self::canonicalize_for_storage( $normalized ); |
| 263 | 239 | |
| 264 | 240 | $plan = self::build_updates( $normalized, $map ); |
| 265 | 241 | |