mirror of
https://github.com/NanmiCoder/MediaCrawler.git
synced 2025-11-25 11:29:27 +08:00
fix(store): 将async for循环替换为async with语句来修复zhihu数据库会话管理
This commit is contained in:
@@ -93,9 +93,9 @@ class ZhihuDbStoreImplement(AbstractStore):
|
|||||||
Args:
|
Args:
|
||||||
content_item: content item dict
|
content_item: content item dict
|
||||||
"""
|
"""
|
||||||
note_id = content_item.get("note_id")
|
content_id = content_item.get("content_id")
|
||||||
async for session in get_session():
|
async with get_session() as session:
|
||||||
stmt = select(ZhihuContent).where(ZhihuContent.content_id == note_id)
|
stmt = select(ZhihuContent).where(ZhihuContent.content_id == content_id)
|
||||||
result = await session.execute(stmt)
|
result = await session.execute(stmt)
|
||||||
existing_content = result.scalars().first()
|
existing_content = result.scalars().first()
|
||||||
if existing_content:
|
if existing_content:
|
||||||
@@ -113,7 +113,7 @@ class ZhihuDbStoreImplement(AbstractStore):
|
|||||||
comment_item: comment item dict
|
comment_item: comment item dict
|
||||||
"""
|
"""
|
||||||
comment_id = comment_item.get("comment_id")
|
comment_id = comment_item.get("comment_id")
|
||||||
async for session in get_session():
|
async with get_session() as session:
|
||||||
stmt = select(ZhihuComment).where(ZhihuComment.comment_id == comment_id)
|
stmt = select(ZhihuComment).where(ZhihuComment.comment_id == comment_id)
|
||||||
result = await session.execute(stmt)
|
result = await session.execute(stmt)
|
||||||
existing_comment = result.scalars().first()
|
existing_comment = result.scalars().first()
|
||||||
@@ -132,7 +132,7 @@ class ZhihuDbStoreImplement(AbstractStore):
|
|||||||
creator: creator dict
|
creator: creator dict
|
||||||
"""
|
"""
|
||||||
user_id = creator.get("user_id")
|
user_id = creator.get("user_id")
|
||||||
async for session in get_session():
|
async with get_session() as session:
|
||||||
stmt = select(ZhihuCreator).where(ZhihuCreator.user_id == user_id)
|
stmt = select(ZhihuCreator).where(ZhihuCreator.user_id == user_id)
|
||||||
result = await session.execute(stmt)
|
result = await session.execute(stmt)
|
||||||
existing_creator = result.scalars().first()
|
existing_creator = result.scalars().first()
|
||||||
|
|||||||
Reference in New Issue
Block a user