Skip to content

Commit c025628

Browse files
authored
Merge pull request #232 from Expensify/neil-shouldSaveCommitCount
Save commitCount when response says to
2 parents 0831ade + 9c6824f commit c025628

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

src/Client.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -703,12 +703,11 @@ private function receiveResponse()
703703
}
704704
} while (is_null($responseLength) || strlen($response) < $responseLength);
705705

706-
// We save the commitCount for future requests. This is useful if for some reason we change the bedrock node we
707-
// are talking to.
708-
// We only set it if process time was returned, which means we did a write. We don't care about saving the commit
709-
// count for reads, since we did not change anything in the DB.
710-
if (isset($responseHeaders['commitCount']) && (($responseHeaders['processTime'] ?? 0) > 0 || ($responseHeaders['upstreamProcessTime'] ?? 0) > 0)) {
711-
$this->commitCount = (int) $responseHeaders['commitCount'];
706+
// Save the commit count if needed.
707+
// In some cases, Auth will return a header instructing the client to save the commit count. It is useful for determining if stale data was used for certain read commands.
708+
// Commit counts are saved for all write commands, identified by process time being non-zero, because it can be useful for future requests if for some reason we change the bedrock node we are talking to.
709+
if ($responseHeaders['shouldSaveCommitCount'] ?? false || (isset($responseHeaders['commitCount']) && (($responseHeaders['processTime'] ?? 0) > 0 || ($responseHeaders['upstreamProcessTime'] ?? 0) > 0))) {
710+
$this->commitCount = (int) ($responseHeaders['commitCount'] ?? 0);
712711
}
713712

714713
// We treat this '555 Timeout', which is a command timeout (not a query timeout), as a ConnectionFailure so that it gets retried regardless of if it is idempotent or not.

0 commit comments

Comments
 (0)