Skip to content

Commit 46c6a25

Browse files
committed
Fix query
1 parent b3b2cef commit 46c6a25

File tree

1 file changed

+23
-6
lines changed

1 file changed

+23
-6
lines changed

workers/handler/src/index.ts

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -93,15 +93,32 @@ async function cachePurgeTag(batch: MessageBatch, env: Env) {
9393
).bind(...tags);
9494
} else {
9595
query = env.DB.prepare(
96-
`SELECT DISTINCT url.id AS id, url.zone AS zone, url.value AS value FROM url LEFT JOIN tag ON url.id = tag.url WHERE url.zone = ? tag.value IN (${tags.map(() => "?").join(", ")})`,
96+
`SELECT DISTINCT url.id AS id, url.zone AS zone, url.value AS value FROM url LEFT JOIN tag ON url.id = tag.url WHERE url.zone = ? AND tag.value IN (${tags.map(() => "?").join(", ")})`,
9797
).bind(zone, ...tags);
9898
}
9999

100-
const { results } = await query.run<{
101-
id: string;
102-
zone: string;
103-
value: string;
104-
}>();
100+
let results: Awaited<
101+
ReturnType<
102+
typeof query.run<{
103+
id: string;
104+
zone: string;
105+
value: string;
106+
}>
107+
>
108+
>["results"];
109+
try {
110+
({ results } = await query.run<{
111+
id: string;
112+
zone: string;
113+
value: string;
114+
}>());
115+
} catch (cause) {
116+
console.error("[Cache Purge Tag] Query Failed", cause);
117+
for (const msg of msgs) {
118+
msg.retry({ delaySeconds: calculateExponentialBackoff(msg.attempts) });
119+
}
120+
continue;
121+
}
105122

106123
// Re-queue all of the tags as URLs.
107124
// sendBatch only allows for a maximum of 100 messages.

0 commit comments

Comments
 (0)