作品投稿時のSlack複数チャンネル投稿を並列化 - #390
Merged
Merged
Conversation
ThreadPoolExecutorを使用してチャンネルへの投稿を並列実行し、 複数チャンネル指定時のレスポンスタイムを改善する。 https://claude.ai/code/session_013vQq3dTD72krdJ1jDuzjQz
ThreadPoolExecutorのワーカースレッドに入る前にメインスレッドで SQLAlchemyのリレーション(account・tags)をプリロードする。 commitによりオブジェクトが期限切れになった状態でスレッドが 属性にアクセスするとSQLiteのクロススレッド制限に違反するため。 https://claude.ai/code/session_013vQq3dTD72krdJ1jDuzjQz
utgwkk
commented
May 16, 2026
Comment on lines
+122
to
+126
| # commit後にSQLAlchemyが全オブジェクトを期限切れにするため、スレッドプールに入る前に | ||
| # メインスレッドでリレーションを読み込んでおく(SQLiteのクロススレッドアクセス禁止対策) | ||
| _ = artwork.title | ||
| _ = artwork.account.name | ||
| _ = [t.name for t in artwork.tags] |
Member
Author
There was a problem hiding this comment.
さすがにあんまりなので、share_to_slack に artwork そのものではなく必要な情報を列挙した引数 (あるいはDTO) を渡すような形にしてほしいナー
Member
Author
There was a problem hiding this comment.
あとは、そもそも並列化する前の関数の呼び出し元でデータを予め用意しておく形になるのであれば、Gyazoへの画像のアップロードも最初の1回だけにするのが収まりよさそう
ArtworkSlackInfo/TagSlackInfoデータクラスを導入し、share_to_slack・ upload_imageがORMオブジェクトに依存しない設計に変更。 呼び出し側でcommit直後にDTOを構築することで、スレッドプール内での SQLiteクロススレッドアクセス問題も根本的に解消する。 https://claude.ai/code/session_013vQq3dTD72krdJ1jDuzjQz
複数チャンネルへ投稿する場合でもGyazoアップロードは1回で済むよう、 upload_imageの呼び出しをスレッドプールの前に移動した。 アップロード済みURLをArtworkSlackInfoのimage_urlフィールドで渡し、 share_to_slackはimage_pathを受け取らない設計に変更。 https://claude.ai/code/session_013vQq3dTD72krdJ1jDuzjQz
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
概要
作品投稿時に複数のSlackチャンネルへ直列で投稿していた処理を、
ThreadPoolExecutorを使って並列化しました。変更の背景
複数チャンネルを指定して投稿する場合、チャンネル数に比例してレスポンスタイムが増加していました。各チャンネルへの投稿は互いに依存しないため、並列化によって待ち時間を短縮できます。
変更内容
api/src/goduploader/graphql/type/mutation/upload_artwork.pyconcurrent.futures.ThreadPoolExecutorをインポートforループをThreadPoolExecutor+executor.map()に置き換え注意点
executor.map()はすべてのスレッドの完了を待ってからリターンするため、後続の Twitter 投稿処理への影響はありませんSHARE_TO_SLACK_WITH_IMAGEの場合、各チャンネルが個別に Gyazo へ画像をアップロードする挙動は変更前と同じです(並列になるだけ)https://claude.ai/code/session_013vQq3dTD72krdJ1jDuzjQz
Generated by Claude Code