|
23 | 23 |
|
24 | 24 | private const PAGINATION_LOOKAHEAD_ROWS = 1; |
25 | 25 |
|
| 26 | + private const ESTIMATE_PROBE_MIN_ROWS = 32; |
| 27 | + |
26 | 28 | public function __construct( |
27 | 29 | private CacheConfig $config, |
28 | 30 | private CacheRuntime $runtime, |
@@ -230,14 +232,30 @@ public function publishCanonical( |
230 | 232 | rootVersion: $state->version, |
231 | 233 | ); |
232 | 234 |
|
233 | | - return $this->store->publishCanonical( |
| 235 | + // Rows publish in guarded slices; membership follows once they are durable. |
| 236 | + if (!$this->store->publishRows( |
234 | 237 | versionKey: $this->keys->version($plan->root), |
235 | 238 | generationKey: $this->keys->generation($plan->root), |
236 | | - membershipKey: $state->key, |
| 239 | + buildingKey: $lease->buildingKey, |
237 | 240 | rowKeys: $rowKeys, |
238 | 241 | rowPayloads: $rowPayloads, |
239 | 242 | expectedVersion: $state->version, |
240 | 243 | expectedGeneration: $state->generation, |
| 244 | + rowTtl: $this->config->rowTtl, |
| 245 | + token: (string) $lease->token, |
| 246 | + leaseTtl: $this->config->buildingLockTtl, |
| 247 | + )) { |
| 248 | + return false; |
| 249 | + } |
| 250 | + |
| 251 | + return $this->store->publishCanonical( |
| 252 | + versionKey: $this->keys->version($plan->root), |
| 253 | + generationKey: $this->keys->generation($plan->root), |
| 254 | + membershipKey: $state->key, |
| 255 | + rowKeys: [], |
| 256 | + rowPayloads: [], |
| 257 | + expectedVersion: $state->version, |
| 258 | + expectedGeneration: $state->generation, |
241 | 259 | membershipPayload: $membership, |
242 | 260 | membershipTtl: $query->configuredTtl() ?? $this->config->queryTtl, |
243 | 261 | rowTtl: $this->config->rowTtl, |
@@ -478,7 +496,10 @@ private function encodeResultWithinLimits(array $rows, CacheState $state): ?stri |
478 | 496 | return null; |
479 | 497 | } |
480 | 498 |
|
481 | | - if ($this->resultExceedsEstimate($rows, $state, $count)) { |
| 499 | + if ( |
| 500 | + $count > self::ESTIMATE_PROBE_MIN_ROWS |
| 501 | + && $this->resultExceedsEstimate($rows, $state, $count) |
| 502 | + ) { |
482 | 503 | return null; |
483 | 504 | } |
484 | 505 |
|
|
0 commit comments