Skip to content

Commit

Permalink
thread pool executor for deletion
Browse files Browse the repository at this point in the history
  • Loading branch information
squeaky-pl committed Sep 25, 2024
1 parent 487e8ab commit aad3b3a
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion bin/remove-message-attachments.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import enum
import logging
from collections.abc import Iterable
from concurrent.futures import ThreadPoolExecutor

import click
from sqlalchemy.orm import Query
Expand Down Expand Up @@ -126,6 +127,8 @@ def run(
assert batch_size > 0
assert delete_batch_size > 0

delete_executor = ThreadPoolExecutor(max_workers=10)

for repetition in range(repeat):
blocks = find_blocks(
limit,
Expand Down Expand Up @@ -167,7 +170,7 @@ def run(
delete_sha256s.add(block.data_sha256)

if len(delete_sha256s) >= delete_batch_size:
delete_batch(delete_sha256s, dry_run)
delete_executor.submit(delete_batch, delete_sha256s.copy(), dry_run)
delete_sha256s.clear()

delete_batch(delete_sha256s, dry_run)
Expand All @@ -177,6 +180,8 @@ def run(

after_id = max_id + 1

delete_executor.shutdown(wait=True)


if __name__ == "__main__":
run()

0 comments on commit aad3b3a

Please sign in to comment.