Skip to content
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 14 additions & 7 deletions api/src/goduploader/graphql/type/mutation/upload_artwork.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import imghdr
import logging
import uuid
from concurrent.futures import ThreadPoolExecutor
from typing import List, Optional

import graphene
Expand Down Expand Up @@ -118,17 +119,23 @@ def mutate_and_get_payload(cls, root, info, files: List[FileStorage], **input):
session.commit()

# 外部サービスへの共有時には Artwork.id に有効な値が設定されている必要があるのでcommit後に共有します
for ch_id in channel_ids:
# commit後にSQLAlchemyが全オブジェクトを期限切れにするため、スレッドプールに入る前に
# メインスレッドでリレーションを読み込んでおく(SQLiteのクロススレッドアクセス禁止対策)
_ = artwork.title
_ = artwork.account.name
_ = [t.name for t in artwork.tags]

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

さすがにあんまりなので、share_to_slackartwork そのものではなく必要な情報を列挙した引数 (あるいはDTO) を渡すような形にしてほしいナー

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

あとは、そもそも並列化する前の関数の呼び出し元でデータを予め用意しておく形になるのであれば、Gyazoへの画像のアップロードも最初の1回だけにするのが収まりよさそう


image_path = top_illust.image_path("full")

def _post_to_channel(ch_id):
try:
share_to_slack(
artwork,
top_illust.image_path("full"),
share_option,
ch_id,
)
share_to_slack(artwork, image_path, share_option, ch_id)
except Exception as e:
logging.error(e)

with ThreadPoolExecutor() as executor:
executor.map(_post_to_channel, channel_ids)

_share_to_twitter(input, current_user, artwork)

return UploadArtwork(artwork=artwork)
Expand Down