Skip to content

Commit 408c373

Browse files
Apply suggestions from code review
Co-authored-by: Lambros Petrou <[email protected]>
1 parent 3ac7599 commit 408c373

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

src/content/docs/d1/best-practices/retry-queries.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ D1 automatically retries read-only queries up to 2 more times when it encounters
1616

1717
## Example of retrying queries
1818

19-
Consider the following example, taken from the [D1 read replication starter template](https://github.com/cloudflare/templates/blob/main/d1-starter-sessions-api-template/src/index.ts#L108).
19+
Consider the following example of a `shouldRetry(...)` function, taken from the [D1 read replication starter template](https://github.com/cloudflare/templates/blob/main/d1-starter-sessions-api-template/src/index.ts#L108).
2020

2121
You should make sure your retries apply an exponential backoff with jitter strategy for more successful retries.
2222
You can use libraries abstracting that already like [`@cloudflare/actors`](https://github.com/cloudflare/actors), or [copy the retry logic](https://github.com/cloudflare/actors/blob/9ba112503132ddf6b5cef37ff145e7a2dd5ffbfc/packages/core/src/retries.ts#L18) in your own code directly.
@@ -25,7 +25,7 @@ You can use libraries abstracting that already like [`@cloudflare/actors`](https
2525
import { tryWhile } from "@cloudflare/actors";
2626

2727
function queryD1Example(d1: D1Database, sql: string) {
28-
const result = await tryWhile(async () => {
28+
return tryWhile(async () => {
2929
return await d1.prepare(sql).run();
3030
}, shouldRetry);
3131
}

src/content/docs/d1/worker-api/return-object.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ The methods [`D1PreparedStatement::run`](/d1/worker-api/prepared-statements/#run
3737
size_after: number, // the size of the database after the query is successfully applied
3838
rows_read: number, // the number of rows read (scanned) by this query
3939
rows_written: number // the number of rows written by this query
40-
total_attempts: number //the number of total attempts to execute read-only, retryable query
40+
total_attempts: number //the number of total attempts to successfully execute the query, including retries
4141
}
4242
results: array | null, // [] if empty, or null if it does not apply
4343
}

0 commit comments

Comments
 (0)