File tree Expand file tree Collapse file tree 2 files changed +13
-14
lines changed Expand file tree Collapse file tree 2 files changed +13
-14
lines changed Original file line number Diff line number Diff line change @@ -105,7 +105,7 @@ async function cachePurgeTag(batch: MessageBatch, env: Env) {
105
105
106
106
// Re-queue all of the tags as URLs.
107
107
// sendBatch only allows for a maximum of 100 messages.
108
- const promises : ReturnType < typeof env . CACHE_PURGE_URL . sendBatch > [ ] = [ ] ;
108
+ const promises : ReturnType < typeof env . DB . batch > [ ] = [ ] ;
109
109
for ( const urlChunk of chunks ( results , 100 ) ) {
110
110
promises . push (
111
111
env . CACHE_PURGE_URL . sendBatch (
@@ -118,23 +118,22 @@ async function cachePurgeTag(batch: MessageBatch, env: Env) {
118
118
contentType : "json" ,
119
119
} ) ,
120
120
) ,
121
- ) ,
121
+ ) . then ( ( ) => {
122
+ const ids = urlChunk . map < string > ( ( { id } ) => id ) ;
123
+ return env . DB . batch ( [
124
+ env . DB . prepare (
125
+ `DELETE FROM tag WHERE url IN (${ ids . map ( ( ) => "?" ) . join ( ", " ) } )` ,
126
+ ) . bind ( ...ids ) ,
127
+ env . DB . prepare (
128
+ `DELETE FROM url WHERE id IN (${ ids . map ( ( ) => "?" ) . join ( ", " ) } )` ,
129
+ ) . bind ( ...ids ) ,
130
+ ] ) ;
131
+ } ) ,
122
132
) ;
123
133
}
124
134
125
135
await Promise . all ( promises ) ;
126
136
127
- const ids = results . map < string > ( ( { id } ) => id ) ;
128
-
129
- await env . DB . batch ( [
130
- env . DB . prepare (
131
- `DELETE FROM tag WHERE url IN (${ ids . map ( ( ) => "?" ) . join ( ", " ) } )` ,
132
- ) . bind ( ...ids ) ,
133
- env . DB . prepare (
134
- `DELETE FROM url WHERE id IN (${ ids . map ( ( ) => "?" ) . join ( ", " ) } )` ,
135
- ) . bind ( ...ids ) ,
136
- ] ) ;
137
-
138
137
for ( const msg of msgs ) {
139
138
msg . ack ( ) ;
140
139
}
Original file line number Diff line number Diff line change @@ -92,7 +92,7 @@ queue = "cache-capture"
92
92
93
93
[[queues .consumers ]]
94
94
queue = " cache-purge-tag"
95
- max_batch_size = 90 # The queue limit is 100, but the D1 binding limit is 100 and sometimes we need a few more params .
95
+ max_batch_size = 95 # The queue limit is 100, but the D1 binding limit is 100 and sometimes we need a few more (i.e. for the zone) .
96
96
97
97
[[queues .consumers ]]
98
98
queue = " cache-purge-url"
You can’t perform that action at this time.
0 commit comments