Skip to content

Commit 36979a0

Browse files
committed
thread pool executor for deletion
1 parent 287642d commit 36979a0

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

bin/remove-message-attachments.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import enum
44
import logging
55
from collections.abc import Iterable
6+
from concurrent.futures import ThreadPoolExecutor
67

78
import click
89
from sqlalchemy.orm import Query
@@ -126,6 +127,8 @@ def run(
126127
assert batch_size > 0
127128
assert delete_batch_size > 0
128129

130+
delete_executor = ThreadPoolExecutor(max_workers=10)
131+
129132
for repetition in range(repeat):
130133
blocks = find_blocks(
131134
limit,
@@ -167,7 +170,7 @@ def run(
167170
delete_sha256s.add(block.data_sha256)
168171

169172
if len(delete_sha256s) >= delete_batch_size:
170-
delete_batch(delete_sha256s, dry_run)
173+
delete_executor.submit(delete_batch, delete_sha256s.copy(), dry_run)
171174
delete_sha256s.clear()
172175

173176
delete_batch(delete_sha256s, dry_run)
@@ -177,6 +180,8 @@ def run(
177180

178181
after_id = max_id + 1
179182

183+
delete_executor.shutdown(wait=True)
184+
180185

181186
if __name__ == "__main__":
182187
run()

0 commit comments

Comments
 (0)