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 Oct 30, 2024
1 parent 81cc80a commit 3589346
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 @@ -3,6 +3,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 @@ -122,6 +123,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 @@ -163,7 +166,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 @@ -173,6 +176,8 @@ def run(

after_id = max_id + 1

delete_executor.shutdown(wait=True)


if __name__ == "__main__":
run()

0 comments on commit 3589346

Please sign in to comment.